老师帮我看一下
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class FileInputStreamDemo {
public static void main(String[] args) {
try {
FileInputStream fs = new FileInputStream("speech.txt");
System.out.print("文本内容:");
// int n = fs.read();
int n=0;
int count = 0;
// while (n != -1) {
// System.out.print((char) n);
// count++;
// n = fs.read();
// }
while((n=fs.read())!=-1){
System.out.print((char)n);
count++;
}
fs.close();
System.out.println();
System.out.println("统计结果:speech.txt文件中共有" + count + "个字符。");
fs.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}


是代码问题吗,输出结果是这样的
6
收起
正在回答
1回答
同学你好,你的代码运行没有问题。speech.txt文件应该在项目下的,与src目录同级。如下:

建议同学重写speech.txt文件内容,再试试。
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
1. Java 零基础入门
- 参与学习 人
- 提交作业 3802 份
- 解答问题 11489 个
本阶段带你迈入Java世界,学习Java必备基础知识,基础语法、面向对象思想以及常用工具类的使用。
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星