pipedwriter
PipedWriter类flush()方法 (PipedWriter Class flush() method)
flush() method is available in java.io package.
flush()方法在java.io包中可用。
flush() method is used to flush this PipedWriter stream and forces characters to be written out of any buffered output.
flush()方法用于刷新此PipedWriter流,并强制从任何缓冲输出中写出字符。
flush() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
flush()方法是一种非静态方法,只能通过类对象访问,如果尝试使用类名称访问该方法,则会收到错误消息。
flush() method may throw an exception at the time of flushing the stream.
flush()方法在刷新流时可能会引发异常。
IOException: This exception may throw when getting any input/output error while performing.
IOException :在执行过程中遇到任何输入/输出错误时,可能引发此异常。
Syntax:
句法:
public void flush();
Parameter(s):
参数:
It does not accept any parameter.
它不接受任何参数。
Return value:
返回值:
The return type of the method is void, it returns nothing.
该方法的返回类型为void ,不返回任何内容。
Example:
例:
// 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());
}
}
}
Output
输出量
pipe_r.read(): A
pipe_r.read(): B
pipe_r.read(): C
翻译自: https://www.includehelp.com/java/pipedwriter-flush-method-with-example.aspx
pipedwriter