I work in Intellij IDEA.

Set levels:

ctrl+shift+alt (Project Structure) -> Sources -> Language level : 7 ctrl+shift+alt (Project Structure) -> Project -> Project language level : 7 ctrl+alt (Setting) -> Compiler -> Java Compiler : 1.7 

Sources code:

 public void setLogProperty(String pathLogProperties) { try (FileInputStream fileInputStream = new FileInputStream(pathLogProperties);) { ... } catch (IOException e) { e.printStackTrace(); } } 

How to solve a problem?

  • Is the project going from an IDE? If this is a gradle project, then the sourceCompatibility value from build.gradle will be used. - Sergey Mitrofanov
  • Yes in IDE, I use Apache Maven. - Giovanni

2 answers 2

I solved the problem by adding the following lines to pom.xml:

 <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <source>1.8</source> <target>1.8</target> </configuration> </plugin> </plugins> </build> 

    in the IDEA settings in the search write JAVA compiler then in the field Target bytecode version change to 1.8

    • I exhibited 1.7, did not help. 1.7 Thank you for trying with resources. - Giovanni
    • if my answer helped you do not forget to rate it - Aslan Kussein