You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
656 B
18 lines
656 B
package w7;
|
|
import java.io.BufferedReader;
|
|
import java.io.FileReader;
|
|
|
|
public class RawCode {
|
|
public static void main(String[] args) {
|
|
int sum = 0;
|
|
// 1. 资源未自动关闭(若中间抛异常,br.close()不会执行)
|
|
BufferedReader br = new BufferedReader(new FileReader("scores.txt"));
|
|
String line;
|
|
while ((line = br.readLine()) != null) {
|
|
// 2. 无数字格式异常处理(若行不是整数,直接崩溃)
|
|
sum += Integer.parseInt(line);
|
|
}
|
|
// 3. 无IO异常处理(文件不存在/读取错误时直接崩溃)
|
|
br.close();
|
|
}
|
|
}
|