java _io_打印流,PrintStream和PrintWriter
发布时间:2020-12-15 05:31:49 所属栏目:Java 来源:网络整理
导读:*PrintStream和PrintWriter,效果相似 PrintStream ps=new PrintStream(字节流,true/false),为真则自动刷新内容,默认为假 System.out默认为PrintStream 打印流 写入文件(通过.println): PrintStream ps=new printStream(new BufferedStream(FileOutputStrea
*PrintStream和PrintWriter,效果相似
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(); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |