Discuss / Java / 文件内容复制

文件内容复制

Topic source
public class CopyFile {
    public static void main(String[] args) throws IOException {
        transferTo(args[0], args[1]);
    }
    static void transferTo(String source, String copy) throws IOException {
        byte[] buffer = new byte[1000];
        try (InputStream input = new FileInputStream(source);OutputStream output = new FileOutputStream(copy);) {
            int n;
            while ((n = input.read(buffer)) != -1) {
                output.write(buffer, 0, n);
            }
        }
    }
}

  • 1

Reply