File.mkdir is not working and I can't understand why
I've this brief snippet:
String target = baseFolder.toString() + entryName;
target = target.substring(0, target.length() - 1);
File targetdir = new File(target);
if (!targetdir.mkdirs()) {
throw new Exception("Errore nell'estrazione del file zip");
}
doesn't mattere if I leave the last char (that is usually a slash). It's done this way to work on both unix and windows. The path is actually obtained from the URI of the base folder. As you can see from baseFolder.toString() (baseFolder is of type URI and is correct). The base folder actually exists. I can't debug this because all I get is true or false from mkdir, no other explanations.The weird thing is that baseFolder is created as well with mkdir and in that case it works.
Now I'm under windows.
the value of target just before the creation of 开发者_运维百科targetdir is "file:/C:/Users/dario/jCommesse/jCommesseDB" if I cut and paste it (without the last entry) in windows explore it works...
The path you provide is not a file path, but a URI. I suggest you try the following :
URI uri = new URI("file://c:/foo/bar");
File f = new File(uri).
It looks, to me, as if the "file:/" at the beginning is the problem... Try getAbsolutePath() instead of toString().
The File
constructor taking a String
expects a path name. A path name is not an URI.
Remove the file:/
from the front of the String (or better yet, use getPath()
instead of toString()
) to get to the path you need.
精彩评论