try with resources in ja code example
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");
}