BufferedWriter write Example
BufferedWriter class write example. This example shows you how to use write method.
BufferedWriter class write example.public void write(int c) throws IOException Writes a single character.
Here is the code
/**
* @ # Write2.java
* A class repersenting use to Write method
* of BufferedWriter class in java.util package
* version 29 May 2008
* author Rose India
*/
import java.io.*;
public class Write2 {
public static void main(String args[]) throws Exception {
// Create a new instance of a BufferedWriter object using
// a StringWriter.
StringWriter stringWriter = new StringWriter();
BufferedWriter bufWriter = new BufferedWriter(stringWriter);
// Write to the underlying StringWriter.
String s = "This is the string being written.";
for (int i = 0; i < s.length(); i++) {
bufWriter.write((char) s.charAt(i));
}
bufWriter.flush();
System.out.println(stringWriter.getBuffer());
}
} |
Output
| This is the string being written. |
|