import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
public class ByteArrayStreamDemo {
public static void main(String[] args) {
// TODO Auto-generated method stub
ByteArrayInputStream bis = new ByteArrayInputStream("asxcd e大山abcd".getBytes());
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int ch = 0;
while((ch=bis.read())!=-1){
bos.write(ch);
}
System.out.println(bos);
//将缓冲区内容转换为字符串
System.out.println(bos.toString());
}
}
以上代码 两行打印的区别。System.out.println(bos);和
System.out.println(bos.toString());,他们各在什么情况下使用? |