1.2 PrintWriter的用法
马 克-to-win:PrintWriter和PrintStream类似,只不过PrintStream是针对字节流的,而PrintWriter是针对字符流的。
例:1.2.1
import java.io.*;
public class TestMark_to_win {
public static void main(String args[]) throws Exception {
String s1 = "我们" + "\n";
String s2 = "你们" + "\n";
PrintWriter p = new PrintWriter("c:/out.txt");
p.println("output" + s1);
p.println("output" + s2);
/*without using the following statement, the file name can be write out, but the content of the file is empty. */
p.close();
}
}
更多请见:https://blog.youkuaiyun.com/qq_44639795/article/details/102600321
PrintWriter使用详解
本文介绍了PrintWriter类的基本用法,并通过示例展示了如何利用PrintWriter将字符串写入文件。此外,还强调了关闭流的重要性,以确保数据正确写入。
782

被折叠的 条评论
为什么被折叠?



