Search code examples
javacompiler-errorstry-with-resources

Resource specification not allowed here for source level below 1.7


I am trying to open an OutputStream resource in a try with resources block:

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

However, I got a compilation error:

Resource specification not allowed here for source level below 1.7

Is there an equivalent for 1.6 or do I have to convert my project to 1.7?


Solution

  • try this code

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