How do I fix "Resource spec is not allowed here for source level below 1.7"?
I had to port my code to 1.6 from 1.8 and I get "Resource specification not allowed here for source level error below 1.7". below u will see the part where I get an eror on the wit line. Try it for now :). What can I do to fix this?
StringBuilder resultKamera2 = new StringBuilder();
{
try (BufferedReader brKamera2 = new BufferedReader(new FileReader("D:/test1.txt"))) {
while ((lineKamera2 = brKamera2.readLine()) != null) {
Matcher categoryMatcherKamera2 = CategorieKamera2.matcher(lineKamera2);
Matcher itemMatcherKamera2 = CategorieSiCantitateKamera2.matcher(lineKamera2);
+3
source to share
1 answer
try with resource instruction, was introduced in Java SE 7. You need to take BufferedReader declaration from parentheses like:
StringBuilder resultKamera2 = new StringBuilder();
{
try {
BufferedReader brKamera2 = new BufferedReader(new FileReader("D:/test1.txt")
while ((lineKamera2 = brKamera2.readLine()) != null) {
Matcher categoryMatcherKamera2 = CategorieKamera2.matcher(lineKamera2);
Matcher itemMatcherKamera2 = CategorieSiCantitateKamera2.matcher(lineKamera2);
And then, to ensure that the stream is closed (try with a resource statement that does this automatically for you), you can put a finally block to close the stream like this:
try {
(...)
} finally {
brKamera2.close();
}
+6
source to share