With try-with-resources writer will be automatically closed:
import org.apache.commons.lang3.StringUtils;
final File file = new File("SomeFile");
try (PrintWriter writer = new PrintWriter(file)) {
writer.print(StringUtils.EMPTY);
}
// here we can be sure that writer will be closed automatically
The above code checks if Directoty exist if not creates the directory, checks if file exists is yes it writes empty string and flushes the buffer, in the end yo get the writer pointing to empty file