请教一个关于IO流的问题

qq_37966597 2017-12-16 09:00:19
package lab11;

import java.io.*;

public class Lab1102 {

public static void main(String[] args) {
try {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("letter.txt"));

int i = 0;
while ((i = bis.read()) != -1) {
System.out.print((char) i);
}

// char c = 0; //循环无法结束
// while ( (c = (char)bis.read() ) != -1 ) {
// System.out.print(c);
// }

bis.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e1) {

}
}
}


while循环那里,如果改成下面注释掉的代码,为什么循环就结束不了了。
...全文
116 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Inhibitory 2017-12-16
  • 打赏
  • 举报
回复
Char is the one data type that isn't signed in java. Its a 16 bit unsigned integer. char 的范围是 [0, 65535]
qq_37966597 2017-12-16
  • 打赏
  • 举报
回复

这是letter.txt里的内容

62,612

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧