Introduction to the various methods involved in IO streams in Java

Source: Internet
Author: User

1 byte stream of Io stream2(1io is used to transfer data between devices.3(2) Classification:4 A: Flow direction5 input stream Read Data6 output stream writes out data7 B: Data type8 Byte stream9 byte input streamTen byte output stream One character Stream A character input stream - character output stream - Note: the A: If you do not specify what points to follow, by default the data type is divided.  - B: It is recommended to use a byte stream unless the file is opened in a Windows-brought notepad that we can read.  -(3) FileOutputStream Write Data - A: Operation procedure + A: Create a byte output stream object - B: Call the Write () method + C: Releasing Resources A              at B: The code reflects: -FileOutputStream fos =NewFileOutputStream ("Fos.txt"); -              -Fos.write ("Hello". GetBytes ()); -              - fos.close (); in              -C: Issues to be aware of? to A: When you create a byte output stream object, +1. Directly call the system's ribbon to create a file 2. Create a FileOutputStream object 3. Point the object to this file -              the B: Why Close () * The first is to make the stream object garbage, so that it can be recycled by the garbage collector, followed by the notification system area to release the resources associated with the file $ C: How to implement the data line wrappingPanax Notoginseng because newline characters are also readable, they are usually wrapped in a line, - D: How to implement append write of data the using a special construction method, the Boolean append parameter is written as true.  +(4) fileinputstream Read Data A A: Operation procedure the A: Create a byte input stream object + B: Call the Read () method - C: Releasing Resources $              $ B: The code reflects: -FileInputStream FIS =NewFileInputStream ("Fos.txt"); -              the             //Mode 1 -             intby = 0;Wuyi              while(by = Fis.read ())! =-1) { theSystem.out.print ((Char) by); -             } Wu              -             //Mode 2 About             byte[] Bys =New byte[1024]; $             intLen = 0; -              while(len = Fis.read (bys))! =-1) { -System.out.print (NewString (Bys,0,len));//Note that the data printed when reading the data must be the last read -                                     //to the actual length of the array, and every time the data is read is the next array of A                                     //The element value of the corresponding position in the array that was covered last +             } the              - fis.close (); $  the  the  the byte stream of Io stream the character input stream -Base class:AbstractReader in                     intRead (): reads one character at a time---> Consistent with the above byte stream operation the                     intReadChar[] CHS): read one character array at a time---> Consistent with the above byte stream operation
 the 
About|--InputStreamReader the|
--FileReader This is a simplified way of generally using this class
                
the|--BufferedReader

the string ReadLine (): reads one string at a time

+|--character output stream base class:Writer

the                voidWriteintch): Write one character at a time

Bayi                voidWriteChar[] CHS,intIndexintlen): Write one part of a character array at a time

the the|--OutputStreamWriter

-|--FileWriter because this class of name simplification generally directly uses this class

-|--BufferedWriter

the                           voidnewLine (): Write a line break

the     voidWrite (string line): writes one string at a time

Introduction to the various methods involved in IO streams in Java

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.