- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 Articles
- What is C++ Standard Output Stream (cout)?
- How to get the Standard Input and Output Stream through Console in C#?
- Getting the Standard Output and Standard Error Output Stream through Console in C#
- How to flush the internal buffer in Python?
- Splitting a slice of bytes after the specified separator in Golang
- The Fruit Flush Diet
- How to Create a Writing Portfolio
- How can I convert bytes to a Python string?
- How to compare two slices of bytes in Golang?
- How to repeat a slice of bytes in Golang?
- How to convert Stream to TreeSet in Java?
- How to display output in javascript?
- What does buffer flush means in C++ ?
- How to obtain the same font in Matplotlib output as in LaTex output?
- Does Process before output and process after input initiate commits in ABAP?

Advertisements