Overview
Widely refers to read and write operations on files
Java IO operations are not only read and write to files, but also read and write to strings, byte arrays, objects, basic data types
Operations are divided into bytes and manipulated by characters. When the requirements of high precision, every byte can not be wrong, such as in the operation of pictures, video, audio and so on by the byte stream to the IO operation, outside the IO operation takes precedence of characters, its efficiency is high
InputStream (byte input stream) implementation class:
FileInputStream
File byte input stream, for file
Created with new FileInputStream (file file)
ObjectInputStream
Acts on a single byte input stream, such as a file (which holds object information) deserialized into an object, which must implement the Serializable interface
Created with new ObjectInputStream (InputStream in)
Returning an object by ReadObject ()
Bytearrayinputstream
byte array input stream, for byte array
Operations IO but does not produce files, in memory, also called memory bytes input stream
Created with new Bytearrayinputstream (byte[] buf)
Bufferedinputstream
Buffer byte input stream, acting on one byte input stream
Created with new Bufferedinputstream (InputStream in)
Common methods:
Read (); // reads the next byte of the stream read (byte[] b); // reads the input stream and exists in byte array B in read (byteintint len); // reads a portion of the input stream and exists in byte array b
OutputStream (byte output stream) Implementation class:
FileOutputStream
File byte output stream, used for file, output content to file
Created by new FileOutputStream (file file) and automatically created if no files exist
Created by new FileOutputStream (file file, Boolean), which can be appended at the end if the file does not exist automatically created
PrintStream
Print stream, parent class is FileOutputStream, used for file or byte output stream
Created with new PrintStream, you can write content to a file
Created by the new PrintStream (output stream out), you can write content to an output stream
The print () parameter can be of many types, which means the flow is very powerful!
ObjectOutputStream
Object serialization stream, acting on a single byte output stream
Used to transfer an object to binary data (write file, send to others), must implement Serializable interface
Created with new ObjectOutputStream (OutputStream out)
Writes an object by WriteObject (object obj)
Bytearrayoutputstream
Array byte output stream, operation IO does not produce file, also called memory byte output stream
Bufferedoutputstream
Buffered byte output stream, acting on a single byte output stream
Created with new Bufferedoutputstream (OutputStream out)
Common methods:
Write (int b); // writes a byte to the output stream write (byte[] b); // writes an array of bytes to the output stream write (byteintint len); // writes the portion of a byte array to the output stream
Reader (character input stream) implementation class:
FileReader
File character output stream, which writes the contents of a file to a stream for use in a file
Created with new FileReader (file file)
BufferedReader
Character buffer input stream, acting on one character input stream
Can read the string directly, which is the only stream in all streams that can read the string directly
Created with new BufferedReader (Reader in)
You can read a line through ReadLine (), return a string of this line, and return NULL if read is complete
InputStreamReader
Conversion stream for converting a byte input stream into a character input flow, acting on a byte input stream
Created with new InputStreamReader (InputStream in)
CharArrayReader
Character array input stream, operation IO does not produce file
Used to write a character array to a stream, acting on a character array
Created with new CharArrayReader (char[] buf)
Common methods:
Read (); // reads a character from the input stream, reads the end return-1read (char[] c); // Reads the input stream into a character array and reads the end return-1read (charintint len); // Reads the part of the input stream into the character array, reads the end returns-1
Writer (character output stream) implementation class:
FileWriter
File character output stream, write stream content to file, for file
File is overwritten by new FileWriter (file file)
Created by new FileWriter (file file) will be appended in the document MO Q
PrintWriter
Print stream, because with PrintStream, this class uses less
OutputStreamWriter
Conversion stream, converting byte output to character output stream for byte output stream
Created with new OutputStreamWriter (OutputStream out)
Chararraywriter
Character array output stream, writes content to character array, operation IO does not produce file
Created with new Chararraywriter ()
BufferedWriter
Character buffered output stream for buffering a character output stream for increased efficiency
Created by new BufferedWriter (Writer out)
Common methods:
Write (int c); // writes a character in the stream to write in C (char[] c); // writes the contents of the stream to the character array Cwrite (charintint len); // writes the portion of the stream to the character output Cwrite (String str); // writes the contents of a stream to a string int int len); // writes a portion of a stream to a string
Java IO Stream