ByteArrayOutputStream writeTo Example

ByteArrayOutputStream class writeTo example. This example shows you how to use writeTo method.


ByteArrayOutputStream class writeTo example. public void writeTo(OutputStream out) throws IOException Writes the complete contents of this byte array output stream to the specified output stream argument, as if by calling the output stream's write method using out.write(buf, 0, count).

Here is the code

/**
 * @ # WriteTo.java
 * A class reprsenting use to writeTo method 
 * of ByteArrayOutputStream class in java.io package
 * version 09 June 2008
 * author Rose India 
 */
import java.io.*;

public class WriteTo {

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

        File file = new File("text.txt");
        FileOutputStream foStream = new FileOutputStream(file);

        ByteArrayOutputStream oStream = new ByteArrayOutputStream();

        String s = "Rose India";
        byte bs[] = s.getBytes();
        //Writes a byte to the byte array output stream.
        oStream.write(bs);

        System.out.println("Stream write into the file ...");
        oStream.writeTo(foStream);
    }
}

Output
Stream write into the file ...

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

HOME | COPYRIGHT | CONTACT US