IO operations (file copy) based on the Java language

    static void main public (String [] args) { 
// Get the value of the system time in milliseconds before starting a copy Long Start = the System. with currentTimeMillis (); // copy file, first set the source file location and destination location of the file File a sourceFile = new new File ( "D: /HAO/movie.mp4"); File descFile = new new File ( "D: /HAO1/movie.mp4"); // read stream BufferedInputStream Reader = null; // InputStream Reader = null; // write inflow BufferedOutputStream The write = null; // write the OutputStream = null; // read cycle, while the read while writing the try { Reader = new new BufferedInputStream ( new new the FileInputStream (a sourceFile)); write = new new BufferedOutputStream The ( new new a FileOutputStream (descFile));
















Reader the FileInputStream new new = // (a sourceFile);
// Write new new = a FileOutputStream (descFile);
// define a B, read byte, byte by byte, for reading and writing
// int B;
/ / while (! (b = reader.read ()) = - 1) {// read
// write.write (b); // write
//}
// or: a character array, the array is read by the press writing the array, increase the efficiency of byte [] = Data new new byte [ 1024]; int len; the while (! (len = reader.Read (Data)) = - . 1) { // read write.write (Data, 0, len ); // write } the System. Out.println ( "the OK"); } the catch (IOException E) { e.printStackTrace (); } the finally { the try { IF (Reader =! null) { reader.Close (); }













} The catch (IOException E) {
e.printStackTrace ();
}
the try {
IF (Write =! Null) {
write.close ();
}
} the catch (IOException E) {
e.printStackTrace ();
}
}
Long the System End = . with currentTimeMillis ();
// Get the value of the system time in milliseconds after the end of copying
the system. Out.println ((Start-end) + "MS");
}

Guess you like

Origin www.cnblogs.com/liusir123/p/11431365.html