Java FileOutputStream Class
Overview
The main purpose of the Java FileOutputStream class is to write data to a file in the file system. The FileOutputStream is a subclass of OutputStream, an abstract superclass.
Constructors
The most used constructors of the class are as follows:
public FileOutputStream(String name) throws FileNotFoundException
public FileOutputStream(File file) throws FileNotFoundException
public FileOutputStream(String name, boolean append) throws FileNotFoundException
public FileOutputStream(File file, boolean append)
throws FileNotFoundException
The boolean value is for appending the new data to the existing file data. The old data in the file will not be deleted if the append boolean value is true.
Methods
The most important methods of the class are:
write() – This method is used to write the byte to the file output stream.
write( byte[] ) – This method is used to write the bytes from the specified byte array to the file output stream.
Example
The below example is to create an object for the class.
FileOutputStream fos = new FileOutputStream(“output.txt”);
—
Java Tutorials
Java Tutorial on this website:
https://www.testingdocs.com/java-tutorial/
For more information on Java, visit the official website :