您的位置:首页 > 编程语言 > PHP开发

ByteArrayOutputStream(字节数组输出流) 示例

2006-06-21 12:56 197 查看
//Demonstrate ByteArrayOutputStream.
import java.io.*;
class ByteArrayOutputStreamDemo{
public static void main(String[] args) throws IOException{
ByteArrayOutputStream f = new ByteArrayOutputStream();
String s = "This should end up in the array";
byte buf[] = s.getBytes();

f.write(buf);
System.out.println("Buffer as a string");
System.out.println(f.toString());
System.out.println("Into array");
byte b[] = f.toByteArray();
for(int i=0;i<b.length;i++){
System.out.print((char)b[i]);
}
System.out.println("/nTo an OutputStream()");
OutputStream f2 = new FileOutputStream("text.txt");
f.writeTo(f2);
f2.close();
System.out.println("Doing a reset");
f.reset();
for(int i=0;i<3;i++){
f.write('X');
}
System.out.println(f.toString());
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: