Java output Stream OutputStream

Source: Internet
Author: User

One: input and output concepts

Input stream (InputStream): For Java programs, writing a file from a program is called an output.

Output stream (OutputStream): For Java programs, reading data from a file to a Java program is called input.

Two: Byte throttle output (OutputStream)

This class is abstract class, public abstract class OutputStream extends Object implements Closeable, Flushable

So if you want to call his method, you need to call it through a subclass, the operation of that class is byte, so it's called the byte output stream.

The action file can be any file.

1: Method:

1:close () closes the byte output stream, freeing the resource, similar to the operation file in Python, and finally needing close.

2:write () This method is an overloaded method that writes the appropriate content to the file.

3:flush () is to flash the cached data into a persistent store (file).

: 2: View its implementation class:

The implementation class has the following:

Let me start with: Fileoutoutstream class.

Fileoutputstreamextends OutputStream

Constructor:

As on the constructor, by binding the file handle. To implement the file operation.

1 Package test14;2 3 import Java.io.File;4 import java.io.FileNotFoundException;5 import Java.io.FileOutputStream;6 import Java.io.OutputStream;7 8  Public classOutputstreamdemon {9      Public Static voidMain (String...args) {Ten  One     } A      Public Static voidoutputstrem (File file) throws filenotfoundexception{ -FileOutputStream fps=Newfileoutputstream (file); -FileOutputStream fps1=NewFileOutputStream ("c:\\new"); the  -     } -}

Where the Append parameter means:

If write true indicates the best write in the text.

1 fileoutputstream  fps1=new FileOutputStream ("c:\\new",True );

Java output Stream OutputStream

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.