1 public class FileReaderDemo { 2 public static void main(String[] args) { 3 File file = new File("f:\\test"); 4 if (!file.exists()) { 5 file.mkdirs(); 6 } 7 String r = file.getAbsolutePath() + "\\1.txt"; 8 String w = file.getAbsolutePath() + "\\2.txt"; 9 FileWriter fw = null; 10 FileReader fr = null; 11 try { 12 fr = new FileReader(r); 13 fw = new FileWriter(w); 14 int len = 0; 15 while ((len = fr.read()) !=-1) { 16 fw.write(len); 17 } 18 // fw.write("abc"); 19 } catch (IOException e) { 20 e.printStackTrace(); 21 } finally { 22 try { 23 fr.close(); 24 fw.close(); 25 } catch (IOException e) { 26 e.printStackTrace(); 27 } 28 } 29 } 30 }
原文:https://www.cnblogs.com/neoo9901/p/13730805.html