Input and Output streams

Source: Internet
Author: User

Character: an abstract object that can be expressed using multiple character schemes or code pages.

For example, Unicode UTF-16 encoding represents a 16-bit integer sequence,

However, Unicode UTF-8 encoding represents the same character as an 8-byte sequence.

The Common Language Runtime uses Unicode UTF-16 (UNICODE conversion format, 16-bit encoding form) to represent characters.

Mark used by people, a symbol in the abstract sense. '1', 'zhong', 'A', '$', '¥ ',......

 

Byte: bytes are the units in which information is transmitted over the network (or stored in hard disk or memory.

The Unit for storing data in a computer. An 8-bit binary number is a very specific storage space. 0x01, 0x45, 0xfa ,......

 

An English letter (case-insensitive) occupies the space of one byte

A Chinese Character occupies two bytes of space.
Symbol: English Punctuation occupies one byte, and Chinese Punctuation occupies two bytes.

 

 

 

ANSI string: in memory, if the "character" exists in the form of ANSI encoding, a character may be expressed in one or more bytes, it is called this character.

The string is an ANSI string or a multi-byte string. "123 Chinese characters" (7 bytes)

Unicode string: in memory, if the "character" exists as the serial number in UNICODE, it is called a unicode string or a wide byte.

String. For example, "123 Chinese characters" (10 bytes)

 
Because different ANSI encoding standards are different, we must know which encoding rule is used for a given multi-byte string, to know which "characters" it contains ". For a unicode string, the content of the "character" represented by it remains unchanged in any environment.

 

 

Input stream (inputstream): a program can read a series of bytes of objects; can read and cannot write

Output stream: can write a series of byte objects to a file; can write can not read

 

Inputstream streaming is an abstract class that does not correspond to a specific input/output device, but only describes the commonality of all stream devices. That is to say, the inputstream class is the parent class of all input streams. All classes corresponding to specific input/output devices in Java are subclasses of the inputstream class.

 

The input stream and output stream are basically the same, but only one read and one write.

 

 

Introduction to common stream classes:

 

File class: it is mainly concerned with the specific attributes of the file, rather than the content of the file. For example, the last modification date of the file is the attributes of the file. File class can also create and delete files

In addition to files and many file-related operations.

 

Inputstream class: it is the parent class of all input streams. It is an abstract class, and there is no specific implementation method in the class at a time. It only defines

Common. The common methods are as follows.

Int read () -- this method reads the content of a byte from the input stream and returns the content of this Byte as an integer. If this parameter is unique

The end of the stream.-1 is returned.

Int read (byte [] B) -- this method reads a certain number of bytes from the input stream and stores them in a byte array. the maximum number of words that can be read at a time

The number of segments is the size of the byte array. If the Stream does not contain byte array size, the return value of this method is

Is the number of bytes actually read. If the array is empty, a null pointer exception is thrown when this method is used.

.

Int read (byte [] B, int off, int Len) -- this method reads len bytes from the specified position of the input stream and stores them in the byte array.

And int read (byte [] B.

Void close () -- this method is used to close the input stream. Release System Resources at the same time.

 

 

Outputstream class: it is the parent class of all output stream classes. It is also an abstract class and does not correspond to a specific output device. Its subclass will correspond to the specific output

Device. The following describes common methods.

Void write () -- this method writes the lowest byte of an integer to the output stream. The highest part of this integer will be ignored.

Void write (byte [] B)

Void close ()

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.