If you don't need to access the instance of FileWriter outside of the try block, you could do this:


public class Test {
void m1() throws IOException {
try(var fileWriter = new...