Aboo Sidhu
Aboo Sidhu

Reputation: 31

Java error try with resource not applicable to variable type

getting error in this line

try (FileInputStream fis = new FileInputStream("E:/encryptedfile.des"))

error: try with resource not applicable to variable type required:java.lang.Autocloseable, found:java.io.file.inputstream.can any one tell me the best solution for that error

Upvotes: 1

Views: 11104

Answers (1)

Adam
Adam

Reputation: 2440

You likely forgot to update the referenced JRE classes on your build path. My bet is that because you aren't using the JDK 7 libraries but rather are still referencing the old libraries. In java 7, you MUST have Autocloseable implemented for all input/output streams. Try to change your referenced classes to the most updated classes possible if you're going to be building against JDK .7.

Edit: If you are using Eclipse...

To change this: Go to Window->Preferences->Java->Installed JRE's and be sure you're pointing to the proper JDK.

Upvotes: 2

Related Questions