在以下发布的代码中,我在 android 中遇到“此语言级别不支持 try-with-resources”的问题,我尝试将语言设置为 7,但它仍然给我同样的例子,而且它一直给我选项更改为语言 7。
public String ReadFile(String fileName) {
try (BufferedReader br = new BufferedReader(new FileReader(fileName+".txt"))) {
StringBuilder sb = new StringBuilder();
String line = br.readLine();
while (line != null) {
sb.append(line);
sb.append(System.lineSeparator());
line = br.readLine();
}
String everything = sb.toString();
return everything;
} catch (FileNotFoundException ex) {
Logger.getLogger(SaveNLoadRank.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(SaveNLoadRank.class.getName()).log(Level.SEVERE, null, ex);
}
return "1";
}