Collation of JAVA IO packages

Source: Internet
Author: User

One: OutputStream class:

Public abstract class OutputStream

Extends Object implements Closeable, flushable

This class is all the parent class that represents the output stream, and all subclasses that inherit the class must implement a write method. The Close,flush,write method is defined in this class.

1.FileOutputStream:

public class FileOutputStream extends OutputStream

This class is used to want to write native data to a file in byte or byet[]. When constructed, you can pass in File,filename, or filedescription.  FileDescription only a single handle to a file, socket, or other data source is logged. Then one thing to note is that in the FileOutputStream constructor, you can specify whether to append data to the write. Then there is a finalize method in this class that is used to ensure that the object has been dropped when it is recycled. That is, in this method, the Close method is actually called.

2.PipedOutputStream

public class PipedOutputStream extends OutputStream

This class is primarily used to write data to the pipeline. The pipeline is used to pass data in a thread. Similarly, this class is also like a pipeline that writes native data: Byte or byte[]. Then, This class is the output of a pipeline. This class of Connect method can be used to connect to a PipedInputStream class object. But this class does not have a finalize method. PS, when the reader of a pipeline wants to read data from a pipeline that does not write data, This thread will be suspended.

3.ByteArrayOutputStream

Bytearrayoutputstream extends OutputStream

This class implements data written to a built-in buff, the buff is defined as byte[], and this class automatically expands the buff. In this class there are two proteccted fields, the buff and the count-record the buff size. Of course, The same class also writes native data, byte,byte[]. The Reset method in the class resets count to 0, which means that the data in this object is zeroed out. You can return the data of the buff by Tobytearray (), or ToString. Of course, You can specify the encoding method when using ToString. Then there is a WriteTo (OutputStream) method that can write the data in the buff directly to another outputstream. In addition, the flush of this class is useless.

Collation of JAVA IO packages

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.