Java PipedWriter close()方法
java.io.PipedWriter.close() 方法关闭此管道输出流并释放与此流相关的所有系统资源。此流可能不再用于编写字符。
1 语法
public void close()
2 参数
无
3 返回值
无
4 示例
package com.yiidian;
/**
* 一点教程网: http://www.yiidian.com
*/
/**
* java.io.PipedWriter.close()方法的例子
*/
import java.io.*;
public class Demo {
public static void main(String[] args) {
// create a new Piped writer and reader
PipedWriter writer = new PipedWriter();
PipedReader reader = new PipedReader();
try {
// connect the reader and the writer
writer.connect(reader);
// write something
writer.write(70);
writer.write(71);
// close the writer
System.out.println("Closing writer...");
writer.close();
System.out.println("Writer closed.");
// print what we wrote
for (int i = 0; i < 2; i++) {
System.out.println("" + (char) reader.read());
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
输出结果为:
Closing writer...
Writer closed.
F
G
热门文章
优秀文章