如何修改它以在 Java 6 上工作?
<小时/>Resource specification not allowed here for source level below 1.7
The type BufferedReader is not visible
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]++;
}
}
}
最佳答案
要使用早期版本的 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();
}
}
}
关于java - try-with-resources- 不允许源级别低于 7,但我需要它在 6 下工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22567663/