I have a variable that I have delared before a try catch block to make sure I can access it outside of the block
/*
Try to get a list of all files.
*/
List<String> result;
try( Stream<Path> walk = Files.walk(Paths.get("data"))){
List<String> result = walk.filter(Files::isRegularFile)
.map(x -> x.toString()).collect(Collectors.toList());
}
catch(Exception e){
e.printStackTrace();
List<String> result = null;
}
ListIterator iter = result.listiterator() // cannot resolve symbol
when I take the original declaration out, I get a cannot resolve symbol error. When I keep it in I get a variable already declared error.
What would be the best way to structure this to use the variable outside of the try except clause?