如何修改它以适用于Java 6?
此处不允许源级别低于1.7的资源规范
BufferedReader类型不可见
public static void findFrequency() throws IOException {
try (BufferedReader ins = new BufferedReader(new FileReader("input.txt"))) {
int r;
while ((r = ins.read()) != -1) {
text=text+String.valueOf((char)r);
freq[r]++;
}
}
}
答案 0 :(得分:1)
要使用早期版本的Java(没有try-with-resources),请进行一些小改动......
BufferedReader ins = null;
try {
ins = new BufferedReader(new FileReader("input.txt"));
// As before...
} finally {
if (ins != null) {
try {
ins.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}