- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试为我的 java 项目编写电话簿(MATSEC 'O' Levels 相当于英国 GCSE),并且在编码(使用 BlueJ)时弹出此错误。我使用老师的书作为引用,没有与错误相关的内容,也没有说我应该添加任何内容。这是我的java代码(不是主类):
import java.io.*;
class Data{
String read(){
String[] name = null;
String[] surname = null;
String[] company = null;
String[] house = null;
String[] street = null;
String[] locality = null;
String[] telno = null;
String[] mobno = null;
int entnum;
BufferedReader txt = new BufferedReader(new FileReader("Directory.txt"));
System.out.println("Name\tSurname\tCompany\tHouse\tStreet\tLocality\tTelephone\tMobile");
System.out.println("\n-----------------------------------------------------------------------------------------------");
for(entnum = 0;name[entnum]!= null; entnum++){
name[entnum] = txt.readLine();
surname[entnum] = txt.readLine();
company[entnum] = txt.readLine();
house[entnum] = txt.readLine();
street[entnum] = txt.readLine();
locality[entnum] = txt.readLine();
telno[entnum] = txt.readLine();
mobno[entnum] = txt.readLine();
System.out.print(name[entnum]+ "\t");
System.out.print(surname[entnum]+ "\t");
System.out.print(company[entnum]+ "\t");
System.out.print(house[entnum]+ "\t");
System.out.print(street[entnum]+ "\t");
System.out.print(locality[entnum]+ "\t");
System.out.print(telno[entnum]+ "\t");
System.out.print(mobno[entnum]+ "\t\n");
}
return null;
}
}
基本上,这只是从文本文件中读取并显示条目。我还没有使用 GUI。
最佳答案
read() 方法中的文件读取代码应包含在 try/catch block 中
(或)
将 read() 方法定义为 read() throws FileNotFoundException { .....}
。
FileNotFoundException
是检查异常,它应该在 throws 子句中声明(或者) 可能抛出此异常的代码应该包装在 try/catch 中,因为 catch/specify要求。
关于java - 错误 : unreported exception java. io.FileNotFoundException;必须被捕获或宣布被扔出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13920527/
能否解释一下proclaim、declaim和declare这三个符号的区别? 最佳答案 它们是 symbols , 不是 keywords . proclaim命名为function使全局化 dec
我正在尝试使现有应用程序尽可能易于访问以进行语音传输。 目前,我有一个 uiviewcontroller,它基本上是一个分页照片 View ,在 uiscrollView (tourScrollVie
选择 UITableViewCell 时,画外音会宣布“已选择”,我不希望画外音说“已选择”。我怎样才能做到这一点? 我尝试过但没有成功的事情: 更改了单元格 accessibilityHint 和
我正在测试一个带有 TalkBack 的 Android 应用程序,“LIST”这个词被宣布为“Fifty first”。显然,TalkBack 假设大写字母“LI”是罗马数字 51。 我无法访问源代
假设 你在 github 上 fork 了一个项目 多人(少于 5 人)正在使用这个 fork 目标是对我们的更改提出 pull 请求 在对我们的分支进行几次提交之后,我们现在想要将我们的分支更新为源
我是一名优秀的程序员,十分优秀!