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: byte[] buffer = new byte[10]; try (InputStream is = new FileInputStream(source); OutputStream os = new FileOutputStream(target, true)) { int i; while ((i = is.read(buffer)) != -1) { System.out.println(new String(buffer, "UTF-8")); os.write(buffer); buffer = new byte[10]; } } } }
Sign in to make a reply
shadowTy