请老师帮检查一下

来源:3-7 自由编程

视线模糊

2020-03-15 11:08:23

package com.imooc.file;


import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.IOException;


public class FileStreamDemo {


public static void main(String[] args) {

// 创建FileInputStream对象

try {

FileInputStream s = new FileInputStream("File\\speech.txt");

System.out.print("文本内容:");

int n = s.read();

int count = 0;//字符统计初始值

while (n != -1) {

System.out.print((char) n);

count += 1;

n = s.read();

}

System.out.println();

System.out.println("统计结果:speech.txt文件中共有" + count + "个字符。");

s.close();


} catch (FileNotFoundException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}


}


}


写回答

1回答

好帮手慕小尤

2020-03-15

同学的程序写法符合题目要求, 继续加油!

如果我的回答解决了你的疑惑,请采纳!祝学习愉快!

0

0 学习 · 11489 问题

查看课程