void close()
描述 (Description)
java.io.PrintStream.close()方法关闭流。 这是通过刷新流然后关闭底层输出流来完成的。
声明 (Declaration)
以下是java.io.PrintStream.close()方法的声明。
public void close()
参数 (Parameters)
NA
返回值 (Return Value)
此方法不返回值。
异常 (Exception)
NA
例子 (Example)
以下示例显示了java.io.PrintStream.close()方法的用法。
package com.iowiki;
import java.io.*;
public class PrintStreamDemo {
public static void main(String[] args) {
String s = "Hello World.";
// create printstream object
PrintStream ps = new PrintStream(System.out);
// print our string
ps.println(s);
// closing stream
System.out.println("Closing Stream...");
// close the stream
ps.close();
}
}
让我们编译并运行上面的程序,这将产生以下结果 -
Hello World.
Closing Stream...