Reputation: 6337
I have code like this:
return (new File(pathA + File.separator + pathB + File.separator)).mkdir();
I believe it used to work, but it does not work now. The application only runs on Linux and we have tested it with Mint 9, Ubuntu 10.04, Kubuntu 12.04, etc. It doesn't create the intended directory.
The path is inside a directory with 777 permissions.
The stack track is not very helpful. Because the trace shows a couple calls to java.security methods, I assume it is a permissions problem. But the actual error message is not helpful at all (probably because the exception handling in the code needs to be improved).
What is the best way to create directories in Java on Linux?
Upvotes: 2
Views: 402
Reputation: 6337
The problem was that in the path I was creating more than one level of directories. The solution was:
return (new File(pathA + File.separator + pathB + File.separator)).mkdirs();
Notice the "s" on mkdirs().
Upvotes: 2
Reputation: 8162
path + File.separator
to a variable. mkdir <INSERT THE PATH TO THE DIR THAT YOUR APP IS TRYING TO CREATE HERE>
That should give you the root cause of your problem.
If that does not make the answer obvious add all other evidence to the question.
Upvotes: 3