File file = new File("C:\\Directory1");
if (!file.exists()) {
if (file.mkdir()) {
System.out.println("Directory is created!");
} else {
System.out.println("Failed to create directory!");
}
}
Above code will make directory for you. Append you id in Path will make directory with your " id ".
Answer from Rahul Rabhadiya on Stack OverflowVideos
You can use java.utils to create a folder inside the resource directory
new File("/path/directory").mkdirs();
"directory" is the name for the folder you want to create
you can get the root of the classpath from new ClassPathResource(".").getFile().getPath() and after that you can append the folder name that you want. after Make the File object by using that full path. and then you can create a folder as you want in the class path.
File txtFile = new File(new ClassPathResource(".").getFile().getPath()+"/tmp");
if (!txtFile.exists()) {
txtFile.mkdirs();
}
Please just run mvn spring-boot:run (use mvnw if maven is not installed or not on path. Spring boot project contains mvnw executable) in the project root without the directory specifier.
./ could be used for unix like systems but not windows.
complete folder is just the root project name in the guide. In your case, the root project name is spring-boot, go to spring-boot directory and run ./mvnw spring-boot:run.
One solution, would be to check if the directory exists:
@Bean
File filesystemRoot() {
File tmpDir = new File("tmp/photo_video_myram");
if (!tmpDir.isDirectory()) {
try {
return Files.createDirectory(tmpDir.toPath()).toFile();
} catch (IOException e) {
e.printStackTrace();
}
}
return tmpDir;
}
You can use isDirectory() method first to check if the directory already exists. In case it does not exist, then create a new one.