Discuss / Java / 练习

练习

Topic source

何以忘言i

#1 Created at ... [Delete] [Delete and Lock User]
package com.itranswarp.learnjava;

import java.io.*;

public class CopyFile {

	public static void main(String[] args) throws IOException {
		if (args.length != 2) {
			System.err.println("Usage:\n  java CopyFile.java <source> <target>");
			System.exit(1);
		}
		copy(args[0], args[1]);
	}

	static void copy(String source, String target) throws IOException {
		// 友情提示:测试时请使用无关紧要的文件
		// TODO:
		try (InputStream input = new FileInputStream(source);
			     OutputStream output = new FileOutputStream(target))
			{
			    input.transferTo(output); 
			    System.out.println("复制成功");
			}
	}
}

何以忘言i

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

eclipse中给main()添加参数的方法:

Run -> Run Configurations... -> Arguments -> Program arguments -> 你的两个文件路径,用空格分开

兄弟你这个能运行嘛


  • 1

Reply