关于我们

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻公共列表

云南大王-java 缓冲区复制文本文件

发布时间:2020-04-13 00:00:00
public class CopyTextByBuf { public static void main(String[] args) { BufferedReader bufr = null; BufferedWriter bufw = null; try { bufr = new BufferedReader(new FileReader("demo_src.txt")); bufw = new BufferedWriter(new FileWriter("demo_desc.txt")); String line = null; //readLine不带行终止符 while ((line = bufr.readLine()) != null) { bufw.write(line); bufw.newLine(); bufw.flush(); } } catch (IOException e) { throw new RuntimeException("读写失败!"); } finally { try { if (bufr != null) bufr.close(); } catch (IOException e) { throw new RuntimeException("读取关闭失败!"); } try { if (bufw != null) bufw.close(); } catch (IOException e) { throw new RuntimeException("写入关闭失败!"); } } } } newLine()无论读一行还是获取多个字符,其实最终都是在硬盘上一个一个读取。所以最终使用的还是read()一次读一个的方法。

/template/Home/Zkeys/PC/Static