Chapter 10 Input/Output and file processing in Java

Source: Internet
Author: User

10.1.1 concept of stream

1). input and output streams

Buffered stream)

10.1.2 input/output stream class library

Data processing can be divided into two types: byte stream and character stream. byte stream is also called binary byte stream) or bit stream (BITS steam ).

Java. Lang. Object->

Inputstream \ outputstream \ reader \ writer \ file \ randomaccessfile

Inputstream->

Fileinputstream \ pipedinputstream \ filterinputstream \ sequenceinputstream \... \ stringbufferinputstream

Outputstream->

Fileoutputstream \ pipedoutputstream \... \ filteroutputstream

Reader->

Pipedreader \ bufferedreader \ filterreader \ inputstreamreader \... \ stringreader

Writer->

Pipedwriter \ bufferedwriter \ filterwriter \ outputstreamwriter \... \ stringwriter

 

-> Filterinputstream->

Bufferedinputstream \ linenumberinputstream \ pushbackinputstream \ datainputstream

-> Filteroutputstream->

Bufferedoutputstream \ dataoutputstream \ printstream

-> Bufferedreader->

Linenumberreader

-> Inputstreamreader->

Filereader

-> Outputstreamwriter->

Filewriter

 

Inputstream \ outputstream \ reader and writer are abstract classes for input and output of data streams, file is a robust class for managing disk files and directories, and randomaccessfile is a stable class for instant access, it is used to perform instant read/write operations on disk files.

 

10.2 use inputstream and outputstream stream

Basic Input and Output streams

Common inputstream Methods

Public int read () reads a byte (8 bit) from the current position in the input stream, Supplements 8 high bytes that are all 0 to form a 16-bit int (0 ~ 255). If no data exists in the current position of the input stream,-1 is returned.

Public int read (byte B []) reads multiple bytes from the current position in the input stream and stores them in array B []. The number of bytes read is also returned.

Public int read (byte B [], int off, int Len) reads len bytes continuously from the current position in the input stream, it is stored at the off + 1 element position of array B [], and the number of bytes read is returned.

Public int available () returns the number of bytes that can be read in the input stream.

Public long SKIP (long n) causes the position pointer to skip n Bytes from the current position

Public void mark () makes a mark at the current position

Public void reset () returns the position pointer to the marked position.

Public void close () closes the connection between the input stream and peripherals and releases the system resources occupied.

 

Common Methods of the outputstream class

Public void write (int B) writes the low byte of parameter B to the output stream

Public void write (byte B []) writes all the bytes in the byte array B [] to the input stream in order

Public void write (byte B [], int off, int Len) Writes len data starting from the off + 1 element in the byte array B [] to the output stream in sequence.

Public void flush () Forcibly clears the buffer and writes data to the peripherals.

Public void close () closes the connection between the output stream and peripherals and releases the system resources occupied.

 

Flush (); Description: writes data in the buffer zone to peripherals, forcibly clears the buffer zone and performs peripheral write operations.

 

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.