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