So I’m trying to create a set of directories from a while loop.
The code for the file creating section is here:
File userDIR=new File("Folder1//"+VARIABLENUMBER+"//"+VARIABLENUMBER+"_Single.txt");
boolean exists = userDIR.exists();
System.out.println(userDIR);//prints correct location
if (!exists) {
System.out.println("does not exist");
userDIR.mkdir();//THIS IS NOT HAPPENING
System.out.println(userDIR.mkdir());//Prints FALSE?
}else{
System.out.println("File Found");
}
If the folder path already exists it says it does… but if I try to create one – it doesn’t work (just kind of skips) or says false…?
Can’t work out what I’m doing wrong?
Thanks for any comments or suggestions.
I think you need to use
userDir.mkdirsnotmkdir.The difference is that the latter will try to create only the directory on the lowest level and if any of the parent directories does not exist it will fail. However,
userDir.mkdirswill create any non-existing parent directories too.