java中讲讲PrintWriter的用法,举例?

1.2 PrintWriter的用法

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.csdn.net/mark_to_win/article/details/71023774

posted @ 2020-12-29 11:09  师徒行者  阅读(215)  评论(0编辑  收藏  举报