Re: Unable to create directory
I`m trying to create a directory for each URL string read in from
a file. However, one of the directories cannot be created, but the
other can. Neither exist at the start. No exception occurs.
Am I missing something obvious? (I have not used mkdir before.)
Your example failed to fail for me here. Both
directories were created, if I deleted them, I
could create them again.
OTOH - I could not resist tweaking your code..
It uses mkdirs() rather than mkdir(). (The 's' is
an important distinction.)
public class DirectoryTree
public static void main ( String args )
BufferedReader infile =
new BufferedReader(new FileReader("URLs.txt"));
String aURL, directory;
while ((aURL = infile.readLine()) != null)
directory = (aURL.replace("http:",""))
String parts = directory.split("/");
File f = new File("cache");
for (int ii=parts.length-1; ii>-1; ii--)
f = new File( f, parts[ii] );
"Creating directory " + f + " . . .");
// important to use makedirs for this variant!
if ((f.mkdirs()) == false)
"Unable to create directory " + directory);
catch (SecurityException e)
catch (IOException e)
Message posted via JavaKB.com