I have the simple code:
try (FileReader file = new FileReader(messageFilePath);
BufferedReader reader = new BufferedReader(file)) {
String line;
while ((line = reader.readLine()) != null) {
////
}
}
I want to write something like that:
FileReader file = null;
///.....
try(file = (file == null ? new FileReader(messageFilePath) : file);
BufferedReader reader = new BufferedReader(file)) {
String line;
while ((line = reader.readLine()) != null) {
////
}
}
It is allows me to reuse FileReader
. Is it possible? If not, how to correctly reuse FileReader
? I use java 8
, if it is important.