Java ByteArrayOutputStream.size()
Syntax
ByteArrayOutputStream.size() has the following syntax.
public int size()
Example
In the following code shows how to use ByteArrayOutputStream.size() method.
/*from ww w. j a v a 2 s . co m*/
import java.io.ByteArrayOutputStream;
import java.io.IOException;
public class Main {
public static void main(String[] args) throws IOException {
int size = 0;
byte[] bs = { 65, 66, 67, 68, 69 };
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (byte b : bs) {
baos.write(b);
String str = baos.toString();
size = baos.size();
System.out.print(size + ":");
System.out.println(str);
}
}
}
The code above generates the following result.
Home »
Java Tutorial »
java.io »
Java Tutorial »
java.io »