A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

本帖最后由 qihuan 于 2015-7-14 11:48 编辑
  1. import java.io.FileReader;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. private static void copy() {
  5.                
  6.                 FileReader fr = null;
  7.                 FileWriter fw = null;
  8.                
  9.                 try {
  10.                         fr = new FileReader("G:\\Demo.txt");
  11.                         fw = new FileWriter("G:\\Demo_copy.txt");
  12.                         
  13.                         char[] buf = new char[1024];
  14.                         int len;
  15.                         while((len = fr.read(buf)) != -1){
  16.                                 fw.write(buf,0,len);
  17.                         }
  18.                 } catch (Exception e) {
  19.                         throw  new RuntimeException("读写失败");
  20.                 } finally {
  21.                         if (fr != null) {
  22.                                 try {
  23.                                         fr.close();
  24.                                 } catch (IOException e) {
  25.                                         // TODO Auto-generated catch block
  26.                                         e.printStackTrace();
  27.                                 }
  28.                         }
  29.                         if (fw != null) {
  30.                                 try {
  31.                                         fw.close();
  32.                                 } catch (IOException e) {
  33.                                         // TODO Auto-generated catch block
  34.                                         e.printStackTrace();
  35.                                 }
  36.                         }
  37.                 }
  38.         }
  39. public static void main(String[] args) throws IOException {
  40.                 copy();
  41.         }
复制代码


2 个回复

倒序浏览
。。。。。。。。。。。。。。
回复 使用道具 举报
学习了~~~
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马