本帖最后由 班志国 于 2012-10-21 08:52 编辑
- import java.io.*;
- class Copy
- {
- public static void main(String[] args)
- {
- copy();
- }
- public static void copy()
- {
- FileReader fr=null;
- FileWriter fw=null;
- try
- {
- fw=new FileWriter("333.txt");
- fr=new FileReader("File.java");
-
- char[] buf=new char[1024];
- int num=0;
- while((num=fr.read(buf))!=-1)
- {
- fw.write(buf,0,num);
-
- }
- }catch(IOException e)
- {
- throw new RuntimeException("读写失败");
- //System.out.println(e.toString());
- }
- finally
- {
- if(fr!=null)
- try{
-
- fr.close();}
- catch(IOException e){System.out.println(e.toString());}
-
- if(fw!=null)
- try{
-
- fw.close();}
- catch(IOException e){System.out.println(e.toString());}
- }
- }
- }
- //编译通过 但没拷贝成功 欢迎 大家找错
复制代码 |