PrintStream Close() Example
Closes the stream.
PrintStreamclass Close() method example. This example shows you how to use Close() method.This method Closes the stream.
Here is the code:-
/**
* @Program that Closes the stream.
* Close.java
* Author:-RoseIndia Team
* Date:-10-Jun-2008
*/
import java.io.*;
public class Close {
public static void main(String[] args) throws IOException {
String c = "Girish Tewari";
//Creating FileOutputStream object
FileOutputStream out = new FileOutputStream("/home/girish/Desktop/g/m.txt");
FileInputStream fin = new FileInputStream("/home/girish/Desktop/g/m.txt");
//Creating PrintStream object
PrintStream ps = new PrintStream(out);
//Appends the specified character sequence to this output stream.
ps.append(c,7,13);
System.out.println("Append successfully");
System.out.print("String after Appending is :");
for (int i = 0; i < c.length(); i++) {
System.out.print((char) fin.read());
}
//Closes the stream.
ps.close();
}
} |
Output of the Program
Append successfully
String after Appending is :Tewari |
|