API Introduction
Defined
FileOutputStream a stream used to write raw bytes such as data. To write a character stream, consider using FileWriter.
Construction method
FileOutputStream: Creates a file output stream that writes data to files represented by the specified file object.
FileOutputStream (File File, Boolean append): Creates a file output stream that writes data to the file that is represented by the specified Files object.
FileOutputStream (FileDescriptor fdobj): Creates an output file stream that writes data to the specified file descriptor, which represents an existing connection to an actual file in the file system.
FileOutputStream (String name): Creates an output file stream that writes data to a file with the specified name.
FileOutputStream (String name, Boolean append): Creates an output file stream that writes data to a file with the specified name.
Common methods
void Write (byte[] b): writes B.length bytes from a specified byte array to this file output stream.
void Write (byte[] b, int off, int len): writes the Len byte in the specified byte array from offset off to this file output stream.
void write (int b): Writes the specified bytes to this file output stream.
Understand
By constructing the method, we know that there are 5 kinds of objects, and briefly introduce several common sources
Public classFileoutputstreamdemo { Public Static voidMain (string[] args)throwsIOException {String str= "Chinese"; byte[]byts=str.getbytes (); File File=NewFile ("A.txt");//File ObjectFileOutputStream fos=NewFileOutputStream (file);//creating a file output stream objectFos.write (Byts); }}/*This is the first: * The value of the file object can not be saved, such as a.txt can not. We create this file ourselves when we export content to it. * The FileOutputStream class inherits the superclass OutputStream of all classes of the byte stream, so the FileOutputStream method cannot put anything out of bytes in write. And there is no way to pass files and strings directly in the file output stream.*/
FileOutputStream---> File output stream (writing data to a file)