Java实现的文件Copy例子
 
这个例子是为一个文件系统管理用的,很粗糙,但能处理过程完整,改造一下可以做成一个copyFile方法。
 
package com.topsoft.icisrpt;

import java.io.*;

/**
* 文件拷贝实现
* File: FileCopyTest.java
* User: leizhimin
* Date: 2008-2-15 11:43:54
*/

public class FileCopyTest {
     public static void main(String args[]) throws IOException {
        FileCopyTest t= new FileCopyTest();
        t.testCopy();
    }

     public void testCopy() throws IOException {
        FileInputStream fin = new FileInputStream( new File( "D:\\projectsCC\\leizhimin_main_TopIcis_V1.6\\IcisReport\\src\\com\\topsoft\\icisrpt\\xslFiles\\R05_QD01.xsl"));
        FileOutputStream fout = new FileOutputStream( new File( "D:\\projectsCC\\leizhimin_main_TopIcis_V1.6\\IcisReport\\src\\com\\topsoft\\icisrpt\\xslFiles\\R05_QD012.xsl"));
         int bytesRead;
         byte[] buf = new byte[4 * 1024];   // 4K
         while ((bytesRead = fin.read(buf)) != -1) {
            fout.write(buf, 0, bytesRead);
        }
        fout.flush();
        fout.close();
        fin.close();
    }
}
 
运行结果显示没问题:)