ByteArrayOutputStream size Example
ByteArrayOutputStream class size example. This example shows you how to use size method.
ByteArrayOutputStream class size example. public int size() Returns the current size of the buffer.
Here is the code
/**
* @ # Size.java
* A class reprsenting use to size method
* of ByteArrayOutputStream class in java.io package
* version 09 June 2008
* author Rose India
*/
import java.io.*;
public class Size {
public static void main(String args[]) throws Exception {
ByteArrayOutputStream oStream = new ByteArrayOutputStream();
String s = "Rose India";
byte b[] = s.getBytes();
// Writes byte array into this byte array output stream.
oStream.write(b);
//Converts the buffer's contents into a string
System.out.println(oStream.toString());
//Size of the buffer.
System.out.println("Size of the output Stream " + oStream.size());
//Closing a ByteArrayOutputStream has no effect.
oStream.close();
}
} |
Output
Rose India
Size of the output Stream 10 |
|