Hello,
I am trying to create a directory in Java. I think I have provided correctly all necessary things so that I make the directory, but it is not created. You can see from my code below and the corresponding output that every element from which I compose the path of the new directory should be correct and valid.
It seems, however, that tDir.mkdir();
is not doing anything, and therefore the success
variable is always false
. I cannot understand why. Thank you in advance.
System.out.println("experimentDir: " + experimentDir);
System.out.println("item.getName(): " + item.getName());
System.out.println("dirName: " + dirName);
String tDirStr = experimentDir + "/" + item.getName() + "All/"
+ dirName + "DataAll";
System.out.println("tDirStr: " + tDirStr);
File tDir = new File(tDirStr);
if (tDir.exists()) {
System.out.println("EXISTS!!!");
} else {
boolean success = tDir.mkdir();
if(success) {
System.out.println("Dir created");
} else {
System.out.println("No dir created!");
}
Output:
experimentDir: /home/Documents/datasets/test-experiments
item.getName(): PosNegReviews
dirName: test
tDirStr: /home/Documents/datasets/test-experiments/PosNegReviewsAll/testDataAll
No dir created!