BufferedWriter write Example
BufferedWriter class write example. This example shows you how to use write method.
BufferedWriter class write example.public void write(String,int,int) throws IOException Writes a portion of a String. If the value of the len parameter is negative then no characters are written.
Here is the code
/**
* @ # Write.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 Write3 {
public static void main(String args[]) throws Exception {
// Create a new instance of a BufferedWriter object using
// a StringWriter.
StringWriter sw = new StringWriter();
BufferedWriter bw = new BufferedWriter(sw);
// Write to the underlying StringWriter.
String str = new String("This is the string being written.");
// Print out the 6 characters.
bw.write(str, 12, 6);
bw.flush();
System.out.println(sw.getBuffer());
// Close the BufferedWriter object and the underlying
// StringWriter object.
sw.close();
bw.close();
}
} |
|