老师帮我看看问题出在哪里
来源:3-7 自由编程
Wonwayshon
2020-06-08 09:39:51
package com.imooc.file1; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; public class File2 { public static void main(String[] args) { FileInputStream fis; try { fis = new FileInputStream("../File/speech.txt"); int a=0; int count=0; System.out.print("文本内容:"); while(a=fis.read()!=-1) { System.out.print((char)a); count++; } fis.close(); } catch (FileNotFoundException e) { e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } System.out.println(); System.out.println("统计结果:speech.txt文件中共有"+count+"个字节"); } }
1回答
同学你好,代码中有如下问题:
1、while条件有误,这里需加上小括号。
(a=fis.read())!=-1
2、count只在try这个区域有效,所以这里的打印语句需调整位置
如果我的回答解决了你的疑惑,请采纳,祝学习愉快~
相似问题