OutputStreamWriter write Example

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


OutputStreamWriter class write example.public void write(char[] , int , int ) throws IOException Writes a portion of an array of characters.

Here is the code

/**
 * @ # Write.java
 * A class repersenting use to write method 
 * of OutputStreamWriter class in java.io package
 * version 03 June 2008
 * author Rose India 
 */
import java.io.*;

public class Write {

    public static void main(String args[]) throws Exception {

        // Create a new instance of a OutputStreamWriter object
        // attached to a ByteArrayOutputStream.
        ByteArrayOutputStream out =
                new ByteArrayOutputStream();
        OutputStreamWriter writer = new OutputStreamWriter(out);

        // Write to the output stream.
        String s = "Random String";
        char[] arr = s.toCharArray();
        // Only write from the 7th character on.
        writer.write(arr, 7, arr.length - 7);
        writer.flush();

        // Display the contents of the ByteArrayOutputStream.
        System.out.println(out.toString());

        // Close the OutputStreamWriter object.
        writer.close();
    }
}

Output
String

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

HOME | COPYRIGHT | CONTACT US