标签:
/* 以 Stream后缀结尾 的都为 字节流, 而以Reader或Writer后缀结尾的叫做字符流 */ class TestFileReaderWriter { public void copyfile() { int c = 0; try { BufferedReader br = new BufferedReader(new FileReader("E:/Postgraduate/Cluster of Qiao‘s thesis/social network/dataset/irise-BufferedReaderWriter.txt"));//缓冲流,效率更高 BufferedWriter bw = new BufferedWriter(new FileWriter("E:/Postgraduate/Cluster of Qiao‘s thesis/social network/dataset/irise-BufferedReaderWriter.txt")); String s = null; for (int i = 0; i < 100; i++) { s=String.valueOf(Math.random()); bw.write(s); bw.newLine(); } bw.flush(); while((s = br.readLine())!=null) System.out.println(s); bw.close(); br.close(); } catch (FileNotFoundException e) { System.out.println("找不到指定文件"); } catch (IOException e) { System.out.println("文件读取错误"); } System.out.println("文件已经复制"); } }
标签:
原文地址:http://www.cnblogs.com/pacoson/p/4491953.html