Java Network Programming --- I/O learning notes

Source: Internet
Author: User

A large part of network programs is simple input and output, that is, moving bytes from one system to another. Bytes are bytes. To a large extent, the data sent by the read server is no different from the data read from the file. There is no difference between transmitting data to the customer and writing a file.

In Java, input and output are organized differently from most other languages. It is built on a stream. Different Basic stream classes (such as java. io. FileInputStream and sun.net. TelnetOutputStream) are used to read and write specific data resources. However, all basic output streams read data using the same basic method.

A filter stream can be connected to an input stream or an output stream. It can modify the data that has been read or written to (for example, encrypted or compressed data), or simply provide additional methods to convert the data that has been read or written to another format.

Reader and Writer can also link to the input stream and output stream to allow the program to read and write text (that is, characters) rather than bytes. If used correctly, Reader and Writer can handle multiple types of character encoding, including multi-byte character sets such as SJIS and UTF-8.

I. output stream

The basic output stream of java is java. io. OutputStream.

Public abstract class OutputStream

N public abstract void write (int B) throws IOException

N public void write (byte [] data) throws IOException

N public void write (byte [] data, int offset, int length) throws IOException

N public void flush () throws IOException

N public void close () throws IOException

The subclass of OutputStream uses these methods to write data to the specified media.

I believe that when we understand what they exist, we will better remember them.

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.