File multiple copies

public  class the FileCopy {
     public  static  void main (String [] args) throws Exception { 
        File F1 = new new File ( " D: \\ \\ demo.doc Test " ); 
        String path = " D: \\ \\ Test " ; 
        . System OUT .print ( " number Please enter the files to be copied: " ); 
        Scanner sc = new new Scanner (. System in );
         int cnt = sc.nextInt (); 

        List <String> List = new newThe ArrayList <String> ();
         for ( int I = 0 ; I <CNT; I ++ ) { 
            the System. OUT .print ( " Please enter " + (I + . 1 ) + " file name: " ); 
            String newName = sc.next (); 
            . the System OUT .println ( " first " + (I + . 1 ) + " name of the file is: " + + newName " .doc " ); 
            List.add (path + + newName".doc");
        }
        list.stream().forEach(x -> System.out.println(x));
        copyToMultipleFiles(f1, list.toArray(new String[0]));
    }

    public static void copyToMultipleFiles(File inFile, String[] outFiles) throws IOException {
        OutputStream[] outStreams = new OutputStream[outFiles.length];
        try {
            for (int i = 0; i < outFiles.length; i++)
                outStreams[i] = new FileOutputStream(outFiles[i]);
            try (InputStream inStream = new FileInputStream(inFile)) {
                byte[] buf = new byte[16384];
                for (int len; (len = inStream.read(buf)) > 0;)
                    for (OutputStream outStream : outStreams)
                        outStream.write(buf, 0, len);
            }
        } finally {
            for (OutputStream outStream : outStreams)
                if (outStream != null)
                    outStream.close();
        }
    }
}

 

Guess you like

Origin www.cnblogs.com/moris5013/p/11535797.html