PipedWriter類flush()方法
- flush() 方法可在
java.io
包。 - flush() 方法用於刷新此 PipedWriter 流並強製從任何緩衝輸出中寫出字符。
- flush() 方法是一個非靜態方法,它隻能通過類對象訪問,如果我們嘗試使用類名訪問方法,那麽我們將得到一個錯誤。
- flush() 方法可能會在刷新流時拋出異常。
IOException:在執行時遇到任何輸入/輸出錯誤時可能會拋出此異常。
用法:
public void flush();
參數:
- 它不接受任何參數。
返回值:
該方法的返回類型是void
,它什麽都不返回。
例:
// Java program to demonstrate the example
// of void flush() method of PipedWriter
import java.io.*;
public class FlushOfPW {
public static void main(String[] args) throws Exception {
int val = 65;
try {
// Instantiates PipedReader and PipedWriter
PipedWriter pipe_w = new PipedWriter();
PipedReader pipe_r = new PipedReader();
// By using connect() method is to connect
// this pipe_w to the given pipe_r
pipe_w.connect(pipe_r);
for (int i = 0; i < 3; ++i) {
// By using write() method is to
// write the val to the stream pipe_w
pipe_w.write(val);
val++;
}
// By using flush() method is to flush
// bytes out to the stream of any buffered
// output
pipe_w.flush();
for (int i = 0; i < 3; ++i) {
// By using read() method is to
// read the integer and convert it into
// char
char ch = (char) pipe_r.read();
System.out.println("pipe_r.read():" + ch);
}
// By using close() method is to close
// the stream
pipe_w.close();
pipe_w.close();
} catch (Exception ex) {
System.out.println(ex.toString());
}
}
}
輸出
pipe_r.read():A pipe_r.read():B pipe_r.read():C
相關用法
- Java PipedWriter connect()用法及代碼示例
- Java PipedWriter close()用法及代碼示例
- Java PipedOutputStream connect()用法及代碼示例
- Java PipedOutputStream close()用法及代碼示例
- Java PipedReader close()用法及代碼示例
- Java PipedReader connect()用法及代碼示例
- Java PipedInputStream connect()用法及代碼示例
- Java PipedOutputStream flush()用法及代碼示例
- Java PipedReader ready()用法及代碼示例
- 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 PipedWriter flush() Method with Example。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。