老师作业求批改点评:
来源:3-7 自由编程
孬帮手慕小菜
2019-12-03 16:37:10
public class Test { public static void main(String[] args) { int n=0;int p = 0; try { //创建一个FileInputStream对象 FileInputStream fis = new FileInputStream("F:\\IO\\test\\speech.txt"); n = fis.read(); System.out.println(n); System.out.println((char)n);//将n转化为字符型输出 System.out.println(); while(n!= -1) { System.out.print((char)n+" "); n=fis.read(); p +=1; } fis.close();//关闭输入流释放资源 } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); }catch (IOException e) { e.printStackTrace(); } System.out.println("文本中有"+p+"个数据"); } }
1回答
同学的程序写法符合题目要求,运行效果没有问题!很棒呐 继续加油~
如果我的回答解决了你的疑惑,请采纳!祝学习愉快!
相似问题