

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to flush output stream after writing bytes
Let us first crate OutputStream with file input.txt −
FileOutputStream fileStream = new FileOutputStream("E:/input.txt"); DataOutputStream dataStream = new DataOutputStream(fileStream);
Now, the writeBytes() method writes out the string to the underlying output stream as a sequence of bytes.
dataStream.writeBytes("Demo text!");
Flush the output stream −
dataStream.flush();
The following is an example. Here, our file is “E:/input.txt” and at the end we are flushing the output stream −
Example
import java.io.DataOutputStream; import java.io.FileOutputStream; public class Demo { public static void main(String[] args) throws Exception { FileOutputStream fileStream = new FileOutputStream("E:/input.txt"); DataOutputStream dataStream = new DataOutputStream(fileStream); dataStream.writeBytes("Demo text!"); dataStream.flush(); dataStream.close(); } }
The output is as follows i.e. the text in the file is −
Output
Demo text!
- Related Questions & Answers
- What is C++ Standard Output Stream (cout)?
- Getting the Standard Output and Standard Error Output Stream through Console in C#
- How to get the Standard Input and Output Stream through Console in C#?
- How to flush the internal buffer in Python?
- What does buffer flush means in C++ ?
- 8085 Program to Exchange 10 bytes
- How can I convert bytes to a Python string?
- How to convert Stream to TreeSet in Java?
- Character Stream vs Byte Stream in Java
- Does Process before output and process after input initiate commits in ABAP?
- How would you convert string to bytes in Python 3?
- Convert bytes to a string in java
- C++ Program to Generate Random Hexadecimal Bytes
- How to display output in javascript?
- Generate Random bytes in Java
Advertisements