Java learning record Day18 (complementary stream)

Day 18

May 19, 2019.
This is the eighteenth day I learn Java.
On this day, I learned the following knowledge.

data flow

Data stream, you can read and write basic data types

  • DataInputStream
    constructor:public DataInputStream(InputStream in) :Create a DataInputStream uses the specified underlying InputStream
    Member method
    public final int read(byte[] b) throws IOException :Some number of bytes read from the input stream contained, and stores them into the buffer array b
    public final int read(byte[] b, int off, int len) throws IOExceptionFrom an input stream will contain up to len bytes read into a byte array

  • DataOutputStream
    constructor:public DataOutputStream(OutputStream out) :Creates a new data output stream to write data to the specified underlying output stream
    Member method
    public void write(int b) throws IOException :The specified byte (the low eight bits of the parameter b) is written to the output stream
    public void write(byte[] b, int off, int len) throws IOExceptionThe specified byte array starting at offset off len bytes written to the output stream

Memory operation flow

Memory operation was conducted without the associated file, not directly read and write file data in the memory operation
characteristics: Invalid This current shutdown, there is no need to close

  • ByteArrayInputStream
    constructor:public ByteArrayInputStream(byte[] buf) :Create a ByteArrayInputStream, using buf as its buffer array
    public ByteArrayInputStream(byte[] buf, int offset, int length)Creating ByteArrayInputStream, using buf as its buffer array
    Member method
    public int read() :From this input stream read the next data byte. 0 to 255 int returns the byte value in the range. If the end of the stream arrive because no byte is available, it returns the value -1
    public int read(byte[] b, int off, int len)Up to len bytes of data from this input stream into a byte array

  • ByteArrayOutputStream
    constructor:public ByteArrayOutputStream() :Creates a new byte array output stream
    public ByteArrayOutputStream(int size)Create a new byte array output stream, with a buffer capacity specified size (in bytes)
    Member method
    public void write(int b) :The specified byte to this byte array output stream
    public void write(byte[] b, int off, int len)Writes the complete contents of this byte array output stream to the specified output stream parameters, which write to the output stream the method calls using the effect out.write (buf, 0, count) as

Print streams

Print streams, only the destination operation, the data source can not operate (can not read data)
Features: can operate any data type, call print () method can write any data type

  • PrintStream : byte stream print
    constructor:public PrintStream(OutputStream out) :Create a new print stream. This stream will not automatically refresh
    Member method
    public void flush() :Flushes the stream
    public void write(byte[] buf, int off, int len)The len bytes from an initial offset specified byte array to write off of this stream
    public void print(int b)Print value

  • PrintWriter : Character print stream
    constructor:public PrintWriter(Writer out) :Create a new PrintWriter, without automatic line flushing
    Member method
    public void flush() :Flushes the stream
    public void write(char[] buf, int off, int len)A partial write an array of characters
    public void print(int b)Print value

Random access stream

A random access stream, is a subclass of class Object. But it combines the InputStream and OutputStream functions, supports reading and writing to a random access file, any type of data can be operated.
Features: can read and write

  • RandomAccessFile
    constructor:public RandomAccessFile(File file, String mode) throws FileNotFoundException :Creating read from and to write to (optional) random access file stream, the file specified by the File parameter
    Member method
    public int read() throws IOException :Read a data file from this byte, returns bytes integer
    public void write(byte[] b, int off, int len) throws IOExceptionThe len bytes written to the file from a specified byte array, starting at offset off
    public void seek(long pos) throws IOExceptionIs provided to measure the beginning of this file file offset pointer, a read or write operation occurs at this position
    public long getFilePointer() throws IOExceptionReturns the current file offset

Serialization

Serialize the object is stored in the file through the flow way Note: To override this object can be serialized Serializable interface
with respect to serialization, deserialization, the object file is stored in a streaming manner to the reduction of objects

  • The ObjectOutputStream : serialization stream
    constructor:public ObjectOutputStream(OutputStream out) throws IOException :Creating ObjectOutputStream writes the specified OutputStream
    Member method
    public final void writeObject(Object obj) throws IOException :Write the specified object ObjectOutputStream

  • The ObjectInputStream : deserialized stream
    constructor:public ObjectInputStream(InputStream in) throws IOException :Create ObjectInputStream reads from the specified InputStream
    Member method
    public final Object readObject() throws IOException, ClassNotFoundException :Reads an object from the ObjectInputStream

note:

transient : transient use keywords, you can declare member variables do not need to serialize, for example:private transient int age ;// 使用transient可以阻止成员变量的序列化

Properties class

Properties, represents a persistent set of properties, can be saved or loaded in the flow from the flow, each key and its corresponding value of the property list is a string, the Hashtable is the parent class, belonging to a set of double row. This collection of keys and values are strings and can not specify generic Properties
constructor:public Properties() :Creating a list of empty property with no default
Member method
public Object setProperty(String key, String value) :Call Hashtable method put
public String getProperty(String key)Search properties in this property list with the specified key
public void load(Reader reader)Reading the key data of the data stored in Properties
public void store(Writer writer, String comments)The Properties collection of key-value pairs data is written to a file, comments Notes

Order flow

Sequence flow represents the logical concatenation of other input streams
constructor:public SequenceInputStream(InputStream s1, InputStream s2) :By remembering these two parameters to initialize the newly created SequenceInputStream (these two parameters will be sequentially read, the first read s1, and then reads the S2), to provide the bytes read from this SequenceInputStream
Member method
public int read(byte[] b, int off, int len) throws IOException :Up to len bytes of data from this input stream into a byte array
public void close() throws IOExceptionCloses this input stream and releases any system resources associated with this stream of

Guess you like

Origin blog.csdn.net/qq_41151659/article/details/90349033