Java IO Stream Learning

Source: Internet
Author: User

1.File only operates on the file itself, and if you want to manipulate its content, you need to use the Randomaccessfile class. (You need to receive the file class object, then proceed, remember closing close)

2. You can use byte stream (InputStream & OutputStream) and character stream (Writer & Reader) when no random access is required.

3. File operation process:

Open a file using the file class;

The output location is specified using subclasses of the byte stream and character stream (since the four operation classes, such as InputStream and writer, are abstract classes);

Perform read & write operations;

Close the file.

4. Byte stream: The main operation is data of type byte

InputStream (Input) && outputstream (output)

A byte type conversion is required between read and write: byte b[] = Str.getbytes ();

String str = new string (b);

Write is divided into: Append and overwrite two kinds, when outputstream instantiation is determined by the parameter.

5. Character stream: The string can be output directly, without the conversion of the format

Reader (read-in, input) && writer (output, write file)

6. The difference between the two:

The character stream is used in buffers (when the file is closed, the buffer contents are written to the file, or the flush () method is actively used for buffer emptying operations. The byte stream operates directly on the file itself and does not use buffers;

7. Generally use byte operations more, characters are only in memory will be formed, so the operation of using bytes is the most.

8. Also use byte stream: Read and write to prevent memory overflow (when the file is large).

Java IO Stream Learning

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.