相同的代码我这里运行没有任何问题
public static void main(String[] args) throws Exception {
FileInputStream in = new FileInputStream("test.txt");
byte[] bytes = new byte[1024];
int len = 0;
while ((len = in.read(bytes)) != -1) {
System.out.println(len);
System.out.println(new String(bytes));
}
in.close();
}
你把 hello world 写在 txt 文件的同一行里面, 再看看结果。
您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~
如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~
ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632
读取到的字符数量是对的,没展示hello可能是IDEA的问题,可以清除缓存并重启试一下