Java-randomaccessfile operation and easy use of IO flow

Source: Internet
Author: User

1.1randomaccessfile--uses RAF to read and write basic type data, and to understand the RAF's pointer operation
Write has a method that corresponds to the write base type
void Seek (Long POS) Adjusts the RAF pointer position to adjust the pointer position at any time when writing
Raf.write (BS); writes a string array GetBytes ("UTF-8")--parses a string into a character array by UTF-8
Raf.read (date); read--The parameter is a created byte array after the byte is placed in the array returns the length of the parameter read to
1.2java io stream, io stream is a Java standard operation for reading and writing data
The flow is divided into two directions:
Input stream output stream
Input stream, InputStream: a stream used to read data from a data source into a program, responsible for reading data operations
Output stream, OutputStream: A stream used to send data out of a program, responsible for writing out data operations
The stream has two classifications:
byte stream, processing flow
BYTE stream: Read and write data must be based on the byte stream, is actually established in the data source and program "Pipeline", responsible for time handling data
Processing flow: The processing stream cannot exist independently, hence the name Incredibles, which is used to process the flow of other streams, and the purpose of processing the other flows is to streamline the read and write operations of their processing streams by processing the flow (processing work is handled by the processing stream)
File stream: The file stream is a pair of low-level streams, where the file input stream is used to read file data, and the file output stream is used to write data to the file.
FileOutputStream supports two common sets of construction methods
FileOutputStream (String Path)
FileOutputStream (File file)
Creates an output stream for the specified file, which defaults to overwrite mode, that is, if the specified file already exists, all data for that file is purged and then all data written out by the stream is saved as data for this file
FileOutputStream (String Path,boolean append)
FileOutputStream (File File,boolean append)
The second parameter is a Boolean value, and if true, the output stream is append mode, that is, the file retains its original data, and all data written out through the current stream is appended to the end of the file.
File input stream, which is used to read the stream of data in a file FileInputStream
Buffered stream Bufferedinputstrram buffered byte input stream
Bufferedoutputstrram buffered byte output stream
Buffered streams are a pair of advanced streams that are capable of accelerating read and write efficiency
A byte array is maintained inside the buffered stream so actually buffering the stream or increasing the amount of read-write data reduces the actual read and write times to improve read and write efficiency, the Bis.read () method actually reads a set of bytes on the first read and returns the first byte, When the method is called again to read a byte, the second byte is returned directly. Until all the bytes are returned, they will actually get a set of bytes back.
Buffered output stream buffer problem--flush (); This method can be implemented when it is necessary to force the data in the cache to be written to memory, and this method is also called within the method when the Close method of the buffered stream is called.
Object Flow Java.io.ObjectOutputStream
Object flow is a pair of advanced streams that allow us to read and write to any object in Java (Object-to-byte conversion works with object flow completion) object output stream, which is used to write out objects in Java (the input of the corresponding object is streamed down)

I am a beginner, if the update is not good, welcome the Great God pointed out, thank you!

More exciting after the update, reprinted annotated!

Java-randomaccessfile operation and easy use of IO flow

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.