Writer Close() Example
Closes the stream, flushing it first.
Writer class Close() method example. This example shows you how to use Close() method.This method Closes the stream, flushing it first.
Here is the code:-
/**
* @Program that Closes a StringWriter
* Close.java
* Author:-RoseIndia Team
* Date:-5-jun-2008
*/
import java.io.*;
public class Close {
public static void main(String[] args){
try
{
StringWriter w = new StringWriter();
w.write("R");
System.out.println("String is: " + w);
//Closes a StringWriter and has no effect
w.close();
w.write("o");
System.out.println("String is: " + w);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
} |
Output of the Program
String is: R
String is: Ro |
|