BufferedWriter write Example

BufferedWriter class write example. This example shows you how to use write method.


BufferedWriter class write example.public void write(char[] ,int, int) throws IOException Writes a portion of an array of characters. Ordinarily this method stores characters from the given array into this stream's buffer, flushing the buffer to the underlying stream as needed.

Here is the code

/**
 * @ # Write1.java
 * A class repersenting use to write method 
 * of BufferedWriter class in java.io package
 * version 29 May 2008
 * author Rose India 
 */
import java.io.*;

public class write1 {

    public static void main(String[] argsthrows 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.";

        char[] arr = s.toCharArray();
        bufWriter.write(arr, 0, arr.length);
        bufWriter.flush();
        System.out.println(stringWriter.getBuffer());

        // Close the BufferedWriter object and the underlying
        // StringWriter object.
        stringWriter.close();
        bufWriter.close();

    }
}

Output
This is the string being written.

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US