gpt4 book ai didi

java - Try-With-Resources示例,编译失败。代码有什么问题

转载 作者:行者123 更新时间:2023-12-02 11:04:23 24 4
gpt4 key购买 nike

import java.io.*;

public class TryWithResources {
public static void main(String[] args) {
try (BufferedReader br = new BufferedReader(new FileReader("C:\\testing.txt")))
{
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}

控制台上的错误消息。我正在使用SpringSource Tool Suite(STS)IDE版本2.7.2。
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
Syntax error on token "(", { expected
Syntax error on token ")", ; expected
Syntax error, insert "}" to complete Block
at TryWithResources.main(TryWithResources.java:9)

第9行是
try (BufferedReader br = new BufferedReader(new FileReader("C:\\testing.txt")))

最佳答案

代码没有错。确保使用Java 7编译器进行编译

关于java - Try-With-Resources示例,编译失败。代码有什么问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22551770/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com