Some basic knowledge of Java I/O operations

Source: Internet
Author: User

1. File classes: Files, also the only separate file class. You can manipulate files. The method is: exists (), delete (), iddirectory (), CreateNewFile (), GetName (), GetPath ()

2. The stream is divided into input and output streams, followed by byte and character input and output streams.
(1) Inputstream,outputstream, which is the input and output stream of the parent class. is the input and output stream of the byte. The main method is read (), when read () =-1 is the end. Write is the output of bytes .
(2) Reader,writer, which is the input and output stream of the parent class. is the input and output stream of the character. The Main method is read (), when read () =-1 is the end. Write is the output of the character .

3. The byte stream is converted into a character flow bridge.
(1) InputStreamReader, this class converts an input stream into a character stream as a byte.
(2) OutputStreamWriter, this class converts the output stream to bytes into a character stream.
For the above class, the conversion, that is, the stream successfully converted into characters, if you want to input, directly with the character stream output can be.

1  Public Static voidMain (string[] args)throwsIOException {2File file1=NewFile ("d:\\", "A.txt");3File file2=NewFile ("d:\\", "B.txt");4FileInputStream fs1=NewFileInputStream (file1);5InputStreamReader f1isr=NewInputStreamReader (FS1);6         //It's not hard to find out that the output byte stream is replaced by a character flow.7FileWriter fw2=NewFileWriter (file2);8         intcontents;9          while((Contents=f1isr.read ())!=-1){Ten Fw2.write (contents); One         } A fs1.close (); - fw2.close (); -}

4.BufferedReader and BufferedWriter
This is a unit of behavior, the operation of the row, the line input and output. The method has a readline () that is equal to Null,newline () to generate a new row.

Some basic knowledge of Java I/O 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.