1.FileInputStream, FileOutputStream Two streams are processing binary files. Mainly processing pictures, videos and so on files.
2.FileInputStream: Reads the contents of the binary file.
3.FileOutputStream: Write binary file.
4.FileInputStream, FileOutputStream Method please refer to:
Http://tool.oschina.net/apidocs/apidoc?api=jdk-zh
5. Copying pictures is the process of reading and writing.
Example one: Copy Picture code Demo
Package com.
Stream;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
public class Testblob {public static void main (string[] args) {file F=new file ("D:\\1.jpg");
File Destination =new file ("E:\\1.jpg");
char context;
try {//1. Create a file input stream to get bytes from the system file FileInputStream fis=new FileInputStream (f);
2. Create a file output stream to write the data to the system file FileOutputStream fos=new FileOutputStream (destination);
SYSTEM.OUT.PRINTLN ("File Size" +fis.available ());
3. Save byte number byte[] B=new byte[fis.available ()];
4. The input stream reads the byte number and saves it to the byte array fis.read (b);
5. Writes a byte array to the destination file Fos.write (b);
System.out.println ("Copy pictures successfully");
6. Finally closes the input and output stream, releases the connection resource Fis.close ();
Fos.close (); catch (FileNotFoundException e) {System.out.println("FileNotFoundException");
E.printstacktrace ();
catch (IOException e) {System.out.println ("IOException");
E.printstacktrace ();
}
}
}
Package com.
Stream;
Import Java.io.File;
Import Java.io.FileInputStream;
Import java.io.FileNotFoundException;
Import Java.io.FileOutputStream;
Import java.io.IOException;
public class CopyPicture {public static void main (string[] args) {file F=new file ("D:\\1.jpg");
File Destination =new file ("E:\\1.jpg");
char context;
try {//1. Create a file input stream to get bytes from the system file FileInputStream fis=new FileInputStream (f);
2. Create a file output stream to write the data to the system file FileOutputStream fos=new FileOutputStream (destination);
SYSTEM.OUT.PRINTLN ("File Size" +fis.available ());
while (Fis.read ()!=-1) {//3. read target file context= (char) fis.read ();
4. Write to target file Fos.write (context);
} System.out.println ("Copy pictures successfully");
5. Finally closes the input and output stream, releases the connection resource Fis.close ();
Fos.close (); The catch (FileNotFoundException e) {System.out.println ("FileNotfoundexception ");
E.printstacktrace ();
catch (IOException e) {System.out.println ("IOException");
E.printstacktrace (); The method assignment picture could not be opened ........