Java IO stream (byte Stream)
Copying files
//Copying Files//using byte streams//copy text file with character stream, copy other format file with byte streamImportJava.io.*; public classindex{ public Static voidMain (string[] Args)throwsexception{//character Stream mode//FileReader FZ = new FileReader ("e:/1.txt"); //FileWriter zt = new FileWriter ("e:/2.txt"); //byte stream modeFileInputStream FZ =NewFileInputStream ("d:/kugou/liu huan-on the way. mp3"); FileOutputStream ZT=NewFileOutputStream ("d:/223.mp3"); intaa; intFz_size = 0;//How big is the statistical file ?AA = Fz.read ();//Read 1 bytes while(aa!= (-1) ) {zt.write (aa);//Write 1 bytesAA = Fz.read ();//Continue reading 1 bytesfz_size++; } //output all remaining content in the stream//when copying a file, write this before closing the file to fully copy the fileZt.flush (); Fz.close (); Zt.close (); System.out.println ("file copy succeeded, total" +fz_size+ "bytes"); }}
Java IO stream (byte stream) copy file