我在获取“令牌上的语法错误”(尝试使用新的Java 7 try-with-resource时,在Eclipse上的“,{expected”)(Eclipse中的BufferReader ..行。)(下面的代码片段)直接从java nio教程http://download.oracle.com/javase/tutorial/essential/io/file.html
复制我将构建路径配置为最新的java7位置,我知道它已正确配置,因为我正在使用其他java.nio功能,如Path和SimpleFileVistor没有任何问题。有什么建议? 谢谢!
try(BufferedReader reader = Files.newBufferedReader(file, charset)) {
String line = null;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
}catch (IOException x) {
System.err.format("IOException in reading " + file.getFileName().toString()+ x);
}
return testCaseNames;
答案 0 :(得分:4)
请检查项目属性中的编译器合规性级别,应该说1.7。您使用的是哪个版本的Eclipse?仅在最近的版本中提供支持 - 请参阅http://thecoderlounge.blogspot.com/2011/07/java-7-support-in-eclipse-371-38-42.html
答案 1 :(得分:2)
Path
和SimpleFileVisitor
是库类,不需要任何特定的编辑器支持新语法。
在Eclipse中,不是JDK编译类,而是Eclipse自己的编译器JDT
。这是应该支持新语法的,并且仅在Eclipse 3.7的最新版本中可用,而不是可以从正常下载页面下载的任何正式版本。