public class CopyFile { public static void main(String[] args) throws IOException { args = new String[] {".\\input.txt",".\\output.txt"}; 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 { // 友情提示:测试时请使用无关紧要的文件 // File inputFile = new File(source); File outputFile = new File(target); try(InputStream fileInputStream = new FileInputStream(inputFile); OutputStream fileOutputStream = new FileOutputStream(outputFile)){ fileInputStream.transferTo(fileOutputStream); } } }
Sign in to make a reply
MayEasLau