Java PrintStream.close()
Syntax
PrintStream.close() has the following syntax.
public void close()
Example
In the following code shows how to use PrintStream.close() method.
/*from ww w . j a va 2 s .co m*/
import java.io.*;
public class Main {
public static void main(String[] args) {
String s = "from java2s.com.";
PrintStream ps = new PrintStream(System.out);
// print our string
ps.println(s);
// closing stream
System.out.println("Closing Stream...");
// close the stream
ps.close();
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »