try with resources example in java
Example: java try with resources
try (PrintWriter writer = new PrintWriter(new File("test.txt"))) {
writer.println("Hello World");
}
try (PrintWriter writer = new PrintWriter(new File("test.txt"))) {
writer.println("Hello World");
}