2
new File(filePath, "/classes/").mkdirs();

filePath is a directory and it exists. classes is a new directory, that should be created

I believe that mkdirs thinks that classes is a file and doesn't do anything, but when I execute

new File(filePath, "/tyhdtyurtu/classes/").mkdirs();

/tyhdtyurtu/classes/ it's created! How to fix this thing? How to create all needed dirs?

UPD: Inside this folder I also have classes.jar file and when I try to create /classes/ dir it fails. But when I try to create, for example, classes1, it works. Why?

UPD2:

System.out.println(new File(apkName, "classes").exists());
System.out.println(new File(apkName, "classes").mkdirs());
System.out.println(new File(apkName, "classes").exists());
System.out.println(new File(apkName, "classes").isDirectory());
System.out.println(new File(apkName, "classes").getAbsolutePath());

Output:

false
true
true
true
C:\Users\Admin\Videos\App\classes

When I copy the link from output to explorer, I see error message that explorer cannot find this path. And if I'm able to create ANY folder except of this, I don't think I have no any permissions

ivan
  • 287
  • 3
  • 14

3 Answers3

1

You need to check 2 things

1. you have write permissions
2. the directory exists or not

you can refer to the following link

http://www.ekiras.com/2015/06/how-to-create-nested-folders-in-java.html

Ekansh Rastogi
  • 2,418
  • 2
  • 14
  • 23
1
  1. Check return value to know whether the dir was created
  2. Use Apache Utils FileUtils.html#forceMkdir(java.io.File) to create directory with all parents if parents do not exist
Pavel Bernshtam
  • 4,232
  • 8
  • 38
  • 62
0

You should code as the followings:

 new File(filePath, "classes").mkdirs();
 new File(filePath, "tyhdtyurtu/classes").mkdirs();
user3359139
  • 430
  • 4
  • 17