package com.aini; //流类rr //流操作的步骤: /*1.找到指定File 2.实例化字节流、InputStream/OutputStream/Reader/Writer 3.读/写文件 4.关闭文件*/ import java.io.*; public class yitop { public static void main(String[] args) { String c = null; BufferedReader bf = null; BufferedWriter bw = null; try { bf = new BufferedReader(new InputStreamReader(new FileInputStream( "txt.txt"))); bw = new BufferedWriter(new OutputStreamWriter( new FileOutputStream("dfas.txt"))); while ((c = bf.readLine()) != null) { // 将字符串写入文件 bw.write(c); System.out.println(c); } bw.close(); bf.close(); } catch (FileNotFoundException e) { System.out.println("找不到指定文件"); } catch (Exception e) { System.out.println("文复制错误"); } System.out.println("文件已复制"); } }
总结: