黑马程序员-JAVA高级视频_IO输入与输出-20天-5(File打印流)
package string.itcastio; import java.io.*; /* * 打印流 * 该流提供了打印方法,可以将各种数据类型的数据都原样打印 * 字节打印流 * PrintStream * 构造函数可以接收的参数类型 * 1,file对象。File * 2,字符串路径。String * 3,字节输出流 。OutputStream * 字符串打印 * PrintWriter * 构造函数可以接收的参数类型 * 1,file对象。File * 2,字符串路径:String * 3,字节输出流: OutputStream * 4,字符输出流:Writer * */ public class PrintStreamDemo { public static void main(String[] args) throws IOException { method(); } public static void method() throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(new FileWriter("a.txt"), true); String line = null; while ((line = br.readLine()) != null) { if ("over".equals(line)) { break; } out.println(line); } br.close(); out.close(); } }