Is there any difference between the two below code snippets, in terms of GC, resource closing etc?
or both are same/correct technically?
#Option 1
try(Writer writer = new OutputStreamWriter(new FileOutputStream(new File(path)), StandardCharsets.UTF_8)) {
}
#Option 2
try(FileOutputStream fis = new FileOutputStream(new File(path);
Writer writer = new OutputStreamWriter(fis, StandardCharsets.UTF_8)) {
}
Just to understand what's the best approach to use in a highly used java application.