Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
public class Demo01 {
public static void Main (string[] args) throws IOException {
TODO auto-generated Method Stub
String file1 = "C:/users/guoyongfeng/desktop/test/a.png";
String file2 = "C:/users/guoyongfeng/desktop/test/b.png";
Create an input stream and an output stream for a file
FileInputStream fis = new FileInputStream (file1);
FileOutputStream fos = new FileOutputStream (file2);
1. Read data from A.png first
int b;
int i = 0;
while ((b = Fis.read ())! =-1) {
i++;
System.out.println (i);
2. After reading the data, write to B.png
Fos.write (b);
}
3. Close the Stream
Fis.close ();
Fos.close ();
System.out.println ("File copy complete ...");
}
}
Use Java IO Stream to make a simple copy of a picture.