IO流问题

//创建 字节 数组  输入流

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()的输出结果会不一样呢?求解答

AJohnson
浏览 1317回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java