import java.io.*; public class Main { public static void main(String[] args)throws IOException{ BufferedReader bd = null; BufferedWriter bw = null; try { bd = new BufferedReader(new FileReader("Demo.txt"));//从Demo.txt文件中读取数据 bw = new BufferedWriter(new FileWriter("Demo_copy.txt"));//写入到Demo_copy.txt中 String line = null; while ((line = bd.readLine())!=null){ bw.write(line); bw.newLine(); bw.flush(); } } catch (IOException e){ System.out.println("读写失败"); } finally { if(bd!=null){ try { bd.close(); } catch (IOException e){ System.out.println("读取关闭失败"); } } if(bw!=null){ try { bw.close(); } catch (IOException e){ System.out.println("写入关闭失败"); } } } } }
io流通过缓冲区读取写入数据
最新推荐文章于 2022-08-03 22:24:45 发布