PipedOutputStream類flush()方法
- flush() 方法可在
java.io
包。 - flush() 方法用於刷新此 PipedOutputStream 並強製從任何緩衝輸出中寫出字節。
- flush() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- flush() 方法可能會在刷新流時拋出異常。
IOException: 獲取任何輸入/輸出錯誤時可能會拋出此異常。
用法:
public void flush();
參數:
- 它不接受任何參數。
返回值:
該方法的返回類型是void
,它什麽都不返回。
例:
// Java program to demonstrate the example
// of void flush() method of PipedOutputStream
import java.io.*;
public class FlushOfPOS {
public static void main(String[] args) throws Exception {
int val = 65;
try {
// Instantiates PipedInputStream and
// PipedOutputStream
PipedInputStream pipe_in = new PipedInputStream();
PipedOutputStream pipe_out = new PipedOutputStream();
// By using connect() method is to
// connect this pipe_out to the given pipe_in
pipe_out.connect(pipe_in);
for (int i = 0; i < 3; ++i) {
// By using write() method is to
// write the val to the stream pipe_out
pipe_out.write(val);
val++;
}
// By using flush() method is to
// flush the stream
pipe_out.flush();
System.out.println("Stream Flushed!!!");
for (int i = 1; i < 4; ++i) {
// By using read() method is to read
// the integer and converted into int
char ch = (char) pipe_in.read();
System.out.println("pipe_in.read():" + ch);
}
// By using close() method is to close
// the stream
pipe_in.close();
pipe_out.close();
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}
輸出
Stream Flushed!!! pipe_in.read():A pipe_in.read():B pipe_in.read():C
相關用法
- Java PipedOutputStream connect()用法及代碼示例
- Java PipedOutputStream close()用法及代碼示例
- Java PipedWriter connect()用法及代碼示例
- Java PipedReader close()用法及代碼示例
- Java PipedWriter flush()用法及代碼示例
- Java PipedReader connect()用法及代碼示例
- Java PipedInputStream connect()用法及代碼示例
- Java PipedReader ready()用法及代碼示例
- Java PipedWriter close()用法及代碼示例
- Java PipedInputStream close()用法及代碼示例
- Java PipedInputStream available()用法及代碼示例
- Java PipedInputStream receive()用法及代碼示例
- Java PriorityQueue size()用法及代碼示例
- Java PushbackReader skip()用法及代碼示例
- Java PriorityBlockingQueue peek()用法及代碼示例
- Java Package getAnnotationsByType()用法及代碼示例
- Java PriorityBlockingQueue take()用法及代碼示例
- Java PriorityBlockingQueue iterator()用法及代碼示例
- Java PriorityBlockingQueue add()用法及代碼示例
- Java Path toAbsolutePath()用法及代碼示例
注:本文由純淨天空篩選整理自Preeti Jain大神的英文原創作品 Java PipedOutputStream flush() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。