java - 对于低于 1.7 的源级别,此处不允许使用资源规范

标签 java compiler-errors try-with-resources

我试图在 try with resources block 中打开 OutputStream 资源:

try (OutputStream output = connection.getOutputStream()) {
    output.write(query.getBytes(charset));
}

但是,我遇到了编译错误:

Resource specification not allowed here for source level below 1.7

是否有 1.6 的等效版本,或者我是否必须将我的项目转换为 1.7?

最佳答案

试试这个代码

try {
    OutputStream output = connection.getOutputStream();
    output.write(query.getBytes(charset));
}catch (Exception e) {
    e.printStackTrace();
}

关于java - 对于低于 1.7 的源级别,此处不允许使用资源规范,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39972926/

相关文章:

java - try-with-resources:Kotlin 中的 "use"扩展功能并不总是有效

java - 客户端服务器tcp重置导致丢包

java - 带有动画的 WindowManager(可能吗?)

java - 服务器信息未更新

c++ - Windows Linux C++编译问题: "no matching function for call"

java - 如何使用 Try-with-Resources 两次使用 PreparedStatement?

Java:将常量存储在非方法接口(interface)或类中更合适吗?

c# - AspNetCompiler - 尝试加载格式不正确的程序

Java 编译器错误。 For 循环不是语句

java - 将 Realm 与 try-with-resources 一起使用是一种好习惯吗?