IO streams (IO streams Summary and Classification)
concept:
* IO stream between devices for processing data transmission .
* Java operations on the data stream by the way.
* Java class for IO operations in the flow package,
* According to the flow into two flows: the input of the output stream.
* Operation type is divided into two streams by:
* Byte stream: byte stream can operate any data , since any data in a computer is stored in the form of bytes.
* Character stream: a stream of characters can only be operated pure character data , more convenient.
IO streams common parent:
* Abstract parent class byte stream:
* InputStream
* OutputStream
* Character stream of abstract superclass:
* Reader
* Writer
IO program written:
* Before use, import classes package IO
* Use, make IO exception handling
* After use, the release of resources
IO流(FileInputStream)
public static void main (String [] args) throws IOException { // the FileInputStream the FileInputStream FIS = new new the FileInputStream ( "xxx.txt"); // Create a stream object int B; the while ! ((B = fis.read ()) = -1) { // read the contents of the file System.out.println (B); } fis.close (); }
IO流(FileOutputStream)
public static void main (String [] args) throws IOException { // create output byte stream object (if not, automatically creates a) a FileOutputStream List = new new a FileOutputStream ( "yy.txt" ); list.write ( 97); // Although int number is written, but the document is to a byte, in addition to automatically take the first three eight. list.write (98 ); list.write ( 99 ); list.close (); }
* Append: If you continue to write to the folder contents, you pass true as the second parameter.
( FileOutputStream list=new FileOutputStream("yy.txt",true);)
IO streams ( copy images )
public static void main (String [] args) throws IOException { the FileInputStream FIS = new new the FileInputStream ( "Photo .jpg"); // Create a byte stream input object a FileOutputStream fos = new new a FileOutputStream ( "copy.jpg"); // Create byte stream output target int B; the while ((B = fis.read ()) = -1!) { // continue to read each byte fos.write (B); // each byte write } fis.close (); // off to release resources flow fos.close(); }
* IO stream to handle data transfer between devices.