Discuss / Java / 作业简洁偷懒版

作业简洁偷懒版

Topic source

细水静流

#1 Created at ... [Delete] [Delete and Lock User]

很简单,但是最终写入的是二进制,大家可以在此基础上修改一下,可以留言讨论!

import java.io.*;

public class CopyFile {
    public static void main(String[] args) throws IOException {
        if (args.length != 2) {
            System.err.println("You must to give 2 parameters!");
            System.exit(1);
        }
        copy(args[0], args[1]);
    }
    static void copy(String source, String target) throws IOException {
        // 读取source内容
        try (InputStream input = new FileInputStream(source);
            OutputStream output = new FileOutputStream(target)) {
                byte[] b = new byte[1024];
                input.read(b);
                output.write(b);
        }
    }
}

  • 1

Reply