views:

171

answers:

3

Hello, 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...

+1  A: 

It looks, to me, as if the "file:/" at the beginning is the problem... Try getAbsolutePath() instead of toString().

+1  A: 

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.

Joachim Sauer
+2  A: 

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).
Olivier Croisier
D'Oh! I missed the obvious constructor!
Joachim Sauer
D'ho! :D Today I'm tired everybody sorry :D
gotch4