1、java拷贝字符文件

2、代码如下:



package Demo1;
import java.io.*;
public class copyfile {

    public static void main(String[] args) {
        try {
            cp();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
    
    public static void cp() throws IOException
    {
        FileWriter fw=null;
        FileReader fr=null;
        char a[]=new char[1024];
        int len=0;
        fr=new FileReader("D:\\Eclipse_jee_java\\javaDemo\\Demo1\\src\\Demo1\\demo1.java");
        fw=new FileWriter("F:\\copy.text");
        while((len=fr.read(a))!=-1)
        {
            fw.write(a, 0, len);
        }
        fr.close();
        fw.close();
    }

}