Package Cn.jbit.copy;import Java.io.bufferedinputstream;import Java.io.dataoutputstream;import java.io.File;import Java.io.fileinputstream;import Java.io.filenotfoundexception;import Java.io.fileoutputstream;import Java.io.ioexception;import Java.io.inputstream;public class Test {/** * @param args */public static void main (string[] Arg s) {///1), create a file object with a filename of "c:\\01.jpg";//2, use a byte stream object to read into memory try {inputstream Filein = new FileInputStream (file);// DataInputStream in = new DataInputStream (Filein);//Use buffers to read objects more efficiently bufferedinputstream in = new Bufferedinputstream ( Filein); FileOutputStream fileout = new FileOutputStream ("D:\\3.jpg");D ataoutputstream dataout = new DataOutputStream (fileOut) ;//Use buffers to write objects more efficiently//bufferedoutputstream dataout=new Bufferedoutputstream (fileout); int temp;while (temp = In.read ())! =-1) {dataout.write (temp);}} catch (FileNotFoundException e) {//Todo auto-generated catch Blocke.printstacktrace ();} catch (IOException e) {//Todo Au To-generated Catch blocke.printsTacktrace ();}}}
Using the byte stream class to read a binary file in Java