Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
public class CopyFile {
public static void Copybytesfile (String sfilename,string dfilename) throws ioexception{
Creating a file input stream object and a file output stream object
The file input stream object is associated with the source file
FileInputStream fis = new FileInputStream (sfilename);
File output stream object associated with a copy file
FileOutputStream fos = new FileOutputStream (dfilename);
Loops through the contents of the file and writes out to the external disk file
Byte[] B = new byte[1024];
/* Read more bytes from the associated source file, save to byte array B, if you reach the end of the file,
* The return value is 1, otherwise the returned value is the actual number of bytes
*/
int read =fis.read (b);
while (Read!=-1) {
Fos.write (b);//write a byte to the associated target file
Read=fis.read (b);
}
Empty the cache, close the Stream object
Fis.close ();
Fos.close ();
}
/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Long t1,t2;
T1= System.currenttimemillis ();
try {
Copyfile.copybytesfile ("A.jpg", "temp.jpg");
} catch (IOException e) {
TODO auto-generated Catch block
E.printstacktrace ();
}
T2= System.currenttimemillis ();
System.out.println ("spents:" + (T2-T1));
}
}
Java fourth time job