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());
}
}
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());
}
}
相关文章推荐
- 输入输出流与字节数组、字符串转换
- c#泛型序列化对象为字节数组的示例
- 关于ByteArrayOutputStream(字节数组输出流)的一个例子,与ByteArrayInputStream作一比较
- JavaSE 高级 第10节 字节数组输出流ByteArrayOutputStream
- 关于ByteArrayOutputStream(字节数组输出流)的一个例子,与ByteArrayInputStream作一比较
- java 文件上传 与 把文件解析成一个字节数组简单的后台示例
- 15.1 ByteArrayInputStream(字节数组输入流)和ByteArrayOutputStream类(字节数组输出流)
- php字符串与byte字节数组转化类示例
- ByteArrayOutputStream(字节数组输出流)的一个例子,与ByteArrayInputStream作一比较
- 蓝牙协议指令和字节数组的关系
- C语言实现双字节在数组中按比特位移动
- C# 16进制与字符串、字节数组之间的转换
- Java byte[]字节数组转换为String字符串的注意事项
- java下整数转成字节数组
- 字节数组 与 十六进制间的转换
- java实现zlib压缩解压缩:文件、byte[]字节数组,数据流
- php实现XML和数组的相互转化功能示例
- Java中字符输入输出流与字节输入输出流的区别
- 合并字节数组
- 字符串 (string)与字节数组(byte[])之间的转换