Most asked top Interview Questions and Answers | Online Test | Mock Test
Education platform for interview prep, online tests, tutorials, and live practice

Build skills with focused learning paths, mock tests, and interview-ready content.

WithoutBook brings subject-wise interview questions, online practice tests, tutorials, and comparison guides into one responsive learning workspace.

Search the library
Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Core Java Interview Questions and Answers

Question: What is FileOutputStream in java?
Answer:

Java.io.FileOutputStream is an output stream for writing data to a File or to a FileDescriptor. Following are the important points about FileOutputStream:

  • This class is meant for writing streams of raw bytes such as image data.

  • For writing streams of characters, use FileWriter

public class FileOutputStream extends OutputStream
Constructors:
1FileOutputStream(File file) 
This creates a file output stream to write to the file represented by the specified File object.
2FileOutputStream(File file, boolean append) 
This creates a file output stream to write to the file represented by the specified File object.
3FileOutputStream(FileDescriptor fdObj) 
This creates an output file stream to write to the specified file descriptor, which represents an existing connection to an actual file in the file system.
4FileOutputStream(String name) 
This creates an output file stream to write to the file with the specified name.
5FileOutputStream(String name, boolean append) 
This creates an output file stream to write to the file with the specified name.
Example:
file = new File("c:/newfile.txt");
fop = new FileOutputStream(file);
if (!file.exists()) {
	file.createNewFile();
} 
// get the content in bytes
byte[] contentInBytes = content.getBytes(); 
fop.write(contentInBytes);
fop.flush();
fop.close();

Save For Revision

Bookmark this item, mark it difficult, or place it in a revision set.

Open My Learning Library
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook