OO Programming with Java


Try with Resource

The code:

try {
  FileWriter f = new FileWriter("output.csv");
  f.write("abc");
  f.close();    
} catch (Exception e) {
  e.printStackTrace();
}

Can be written:

try (FileWriter f = new FileWriter("output.csv")) {
  f.write("abc");
}