1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
| import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.StringReader; import java.nio.file.LinkPermission;
public class demo01 { public static void main(String[] args) { testCopy(); }
public static void testCopy(){ long start = 0 , end = 0; start = System.currentTimeMillis(); Copy("test//demo01.txt","test//demo02.txt","test//demo02.txt"); end = System.currentTimeMillis(); System.out.println("完成时间: "+ (end-start)+" ms"); }
public static void Copy(String sourceName, String targetName, String redName){ FileInputStream input = null; FileInputStream input2 = null; FileOutputStream output = null; try { input = new FileInputStream(sourceName); output = new FileOutputStream(targetName); input2 = new FileInputStream(redName); int lenth = -1; int lenth2 = -1; byte[] bytes = new byte[1024]; while ((lenth = input.read(bytes))>-1){ output.write(bytes); } while ((lenth2 = input2.read(bytes))>-1){ String str = new String(bytes); System.out.println(str); } }catch (IOException e){ e.printStackTrace(); }finally { try { if (input != null) input.close(); }catch (IOException e){ e.printStackTrace(); } try { if (output != null) output.close(); }catch (IOException e){ e.printStackTrace(); }
} } }
|