//创建 字节 数组 输入流
String intput ="elephant";//输入的字符串内容
byte[] buffer=intput.getBytes();
ByteArrayInputStream bais =new ByteArrayInputStream(buffer);//创建字节数组输入对象
for(int i=0;i<intput.length();i++){
while(((int)bais.read())!=-1){
System.out.println((char)bais.read());
}
}
输出结果:
l
p
a
t
//创建 字节 数组 输入流
String intput ="elephant";//输入的字符串内容
byte[] buffer=intput.getBytes();
ByteArrayInputStream bais =new ByteArrayInputStream(buffer);//创建字节数组输入对象
for(int i=0;i<intput.length();i++){
int c;
while((c=bais.read())!=-1){
System.out.println((char)c);
}
}
输出结果:
e
l
e
p
h
a
n
t
为什么c=bais.read(),(char)c和(char)bais.read()的输出结果会不一样呢?求解答
相关分类