outputstream.flush()
时间: 2024-05-08 20:15:18 浏览: 77
The flush() method in OutputStream class flushes the buffered output stream. It forces any buffered output bytes to be written out to the underlying output stream.
In other words, it is used to ensure that all the data that has been written to the output stream is actually sent out and not sitting in some internal buffer.
Here is an example of how to use the flush() method:
```java
OutputStream os = new FileOutputStream("output.txt");
os.write("Hello World".getBytes());
os.flush();
os.close();
```
In the above example, we are creating a FileOutputStream object and writing a string "Hello World" to it. After writing the data, we call the flush() method to ensure that all the data is sent to the file. Finally, we close the output stream.
阅读全文