java _io_打印流,PrintStream和PrintWriter
*PrintStream和PrintWriter,效果相似
PrintStream ps=new PrintStream(字节流,true/false),为真则自动刷新内容,默认为假System.out默认为PrintStream 打印流写入文件(通过.println):PrintStream ps=new printStream(new BufferedStream(FileOutputStream("vv.txt")),true)ps.println("ad")重定向输出端(输出到文件):System.setOut(ps); ps.println("aa");重定向回控制台:System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));PrintStream:
//打印流System.out PrintStream os =System.out; os.println("haha"); //写入文件 os= new PrintStream(new BufferedOutputStream(new FileOutputStream("vv.txt")),true); os.println("add"); os.println(false); os.flush(); os.close() //重定向输出端(输出到文件) System.setOut(os); System.out.println("change"); //重定向回控制台 System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true)); //标准的输入输出端
PrintWriter:
PrintWriter pw=new PrintWriter(new BufferedOutputStream(new FileOutputStream("vv.txt")),true); pw.println("ff"); pw.println(true); pw.close();
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。