<<< Static methods of the Files class | Index | File info >>> |
Code that creates a directory if it doesn't already exist
String dirString = "c:/java/files"; Path dirPath = Paths.get(dirString); if (Files.notExists(dirPath)) { Files.createDirectories(dirPath); }
Code that creates a file if it doesn't already exist
String fileString = "myfile.txt"; Path filePath = Paths.get(dirString, fileString); if (Files.notExists(filePath)) { Files.createFile(filePath); }
<<< Static methods of the Files class | Index | File info >>> |