Problem statement : Want to check if a file exists or not at given location and create if not to avoid FileNotFoundexception Solution : using Java public void createFileIfDoesNotExists() throws IOException { File usersHTMLFile = new File(System.getPr...
Markdown supported · ⌘↵ to post
Wellington Domiciano
Nice! I like to use the
Filesutility class, look:import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Main { public static void main(String... args) throws IOException { final Path path = Paths.get(System.getProperty("user.dir"), "Report.html"); if (Files.notExists(path)) Files.createFile(path); } }