Java Exception try-with-resources simplified for Java 9
import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class Main { public static void main(String[] args) { try {//from ww w. ja v a2 s.com writeFile(new BufferedWriter( new FileWriter("Main.java")), "This is easy in Java 9"); } catch (IOException ioe) { System.out.println(ioe); } } public static void writeFile(BufferedWriter writer, String text) { try (writer) { writer.write(text); } catch (IOException ioe) { System.out.println(ioe); } } }