Android IO stream re-review

Source: Internet
Author: User

Before learning io fuzzy fuzzy, now write down, easy to understand, and later more familiar with ease. (Long-term update)

The concept of the main.

Before we learn, we need to understand the concept of byte and character.

Character streams are processed in characters (16-bit binary) and are used primarily for Unicode data such as text files.

Byte streams are processed in bytes (8-bit binary) and are mainly used to read and write binary data such as pictures, sounds, and video.

Here can be so simple to understand, such as Chinese characters, Chinese characters is a character, involving the use of characters in the text of Chinese characters.

In most cases, the byte stream is more prevalent because most operands are based on the byte stream.

Input status

byte Array (bytes)

FileInputStream ()//create file input stream

Bufferedinputstream ()///Create a buffered input to read large files, this method is more efficient.

(character stream) String

FileReader ()//Ibid.

BufferedReader ()//Ibid.

Output brief summary input changed to output, reader to write (Steal a bit lazy)

Sometimes, it takes character bytes to be used, and it needs to be converted to each other.

InputStream provides a byte stream reading, not a text read, read by reader is a char array or a string, and InputStream is used to read the bytes array.
The reader class and its subclasses provide a stream of characters read Char,inputstream and its subclasses provide a byte stream for reading bytes, so the FileReader class reads the file as a stream of characters, FileInputStream reads the file by byte stream InputStreamReader can convert a read like stream into a character stream, a bridge between reader and stream.

InputStreamReader (Byte to character)

When the text is stored locally, the character form, the reading is placed on the display, it needs to be converted to byte form, and subsequent operations are performed.

OutputStreamWriter (reverse)

In general, when saving the display to local, the bytes need to be converted into character form.

Stick to the article I'm looking at here.

Http://www.cnblogs.com/sjjsh/p/5269781.html

The last is the question which bothers me for a long time, about the usage scene of the character stream of the byte stream.

I've roughly sorted out the next

Requirement 1: Copy a text file
1. Clear source and destination    Source:   inputstream   Reader    Purpose: OutputStream  Writer 2. Is it plain text?    Source:   Reader    Purpose: Writer 3. Specific device    Source:   HDD     file    Purpose: Hard drive     file    FileReader fr = new FileReader ("A.txt");    FileWriter FW = new FileWriter ("B.txt"); 4. Whether additional features need to be     efficient, convert     bufferedreader br = new BufferedReader (New FileReader ("A.txt"));     

  

Requirement 2: Read keyboard input information, write to a file

1. Clear source and destination     Source:   inputstream    Reader     Purpose: OutputStream   Writer 2. Is it plain text?     Source:   Reader     Purpose: Writer 3. Device:     Source:   keyboard     system.in     Purpose: Hard disk     File     InputStream in = system.in;     FileWriter FW = new FileWriter ("B.txt");     Converts the read byte data into a string, which is then manipulated by the character stream-4. Do you need additional functionality?     need to convert: Stream bytes into character streams because the explicit source is Reader, which makes it easier to manipulate text data. So, to convert an existing byte stream into a character stream. Use byte-to-character object      InputStreamReader ISR = InputStreamReader (system.in);     FileWriter FW = new FileWriter ("B.txt");     Need to be efficient:         bufferedreader br = new BufferedReader (new InputStreamReader (System.int));         

  

Requirement 3: Display a text file data on the console

1. Clear source and destination         Source:   inputstream   Reader         Purpose: OutputStream  Writer     2. Is it plain text?         Source:   Reader         Purpose: Writer     3. Specific equipment:         Source:  HDD      File         Purpose: Console    System.out         FileReader FR = new FileReader ("A.txt");         OutputStream OS = new OutputStream (System.out); PrintStream     4. Additional functionality required:         convert         filereader fr = new FileReader ("a.txt") required;         OutputStreamWriter OSW = new OutputStreamWriter (system.out);         Requires efficient         bufferedreader br = new BufferedReader (New FileReader ("A.txt"));         

There are many not mentioned, will be added in the future, long-term update.

Android IO stream re-review

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.