标签:package public pack ade put log main reader stream
1 package demo05; 2 3 import java.io.BufferedReader; 4 import java.io.File; 5 import java.io.FileNotFoundException; 6 import java.io.FileOutputStream; 7 import java.io.FileReader; 8 import java.io.FileWriter; 9 import java.io.IOException; 10 import java.io.PrintWriter; 11 12 public class PrintWriterDemo { 13 public static void main(String[] args) throws IOException { 14 File file = new File("c:\\1.txt"); 15 PrintWriter pw = new PrintWriter(file); 16 //原样输出 17 pw.println(100); 18 pw.flush(); 19 pw.close(); 20 21 FileOutputStream fos = new FileOutputStream("c:\\2.txt"); 22 PrintWriter pw1 = new PrintWriter(fos, true); //自动刷新 23 pw1.println("java"); 24 pw1.close(); 25 26 //文件复制 27 BufferedReader bfr = new BufferedReader(new FileReader("c:\\3.txt")); 28 PrintWriter pw11 = new PrintWriter(new FileWriter("d:\\3.txt")); 29 String line = null; 30 while ((line = bfr.readLine()) != null) { 31 pw11.println(line); 32 } 33 pw11.close(); 34 bfr.close(); 35 } 36 37 38 }
标签:package public pack ade put log main reader stream
原文地址:http://www.cnblogs.com/lwn007/p/6920332.html