I had to move my code to 1.6 from 1.8, and i get "Resource specification not allowed here for source level below 1.7" error. below u will see part wher i get the eror at line wit Try and while:). 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);
try with resources statement was introduced in Java SE 7. You need to take the BufferedReader declaration out of the parentheses like 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);
And then, to ensure that the stream will be closed (try with resources statement does that automatically for you) you can put a finally block to close the stream like this:
try {
(...)
} finally {
brKamera2.close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With