Unable to create directory

Discussion in 'Java' started by Alan, Oct 8, 2007.

  1. Alan

    Alan Guest

    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.)

    I am running on the Windows Vista OS. Thanks, Alan

    Output:

    http://www.weather.gov/
    Creating directory www.weather.gov . . .
    Unable to create directory www.weather.gov
    http://www.cnn.com/
    Creating directory www.cnn.com . . .

    Code:

    import java.io.*;
    import java.lang.*;

    public class create_directory
    {
    public static void main ( String[] args ) throws IOException
    {
    try
    {
    BufferedReader infile = new BufferedReader(new
    FileReader("URLs.txt"));

    String aURL, directory;

    while ((aURL = infile.readLine()) != null)
    {
    System.out.println(aURL);
    directory = (aURL.replace("http:","")).replace("/","");
    System.out.println("Creating directory " + directory + " . . .");
    try
    {
    if ((new File(directory).mkdir()) == false)
    System.out.println("Unable to create directory " + directory);
    }
    catch (SecurityException e) {e.printStackTrace();}
    }
    infile.close();
    }
    catch (IOException e) {e.printStackTrace();}
    }

    }
    Alan, Oct 8, 2007
    #1
    1. Advertising

  2. Alan

    Alan Guest

    Strange . . . This happens under Windows Vista and Java SE JDK 1.6,
    but it does not happen under Windows 98SE and JDK 1.5.

    Alan
    Alan, Oct 8, 2007
    #2
    1. Advertising

  3. Alan wrote:
    >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.)

    <sscce>
    import java.io.*;
    import java.lang.*;

    public class DirectoryTree
    {

    public static void main ( String[] args )
    {
    try
    {
    BufferedReader infile =
    new BufferedReader(new FileReader("URLs.txt"));

    String aURL, directory;

    while ((aURL = infile.readLine()) != null)
    {
    System.out.println(aURL);
    directory = (aURL.replace("http:",""))
    .replace("/","")
    .replace(".","/");
    String[] parts = directory.split("/");
    File f = new File("cache");
    for (int ii=parts.length-1; ii>-1; ii--)
    {
    f = new File( f, parts[ii] );
    }
    System.out.println(
    "Creating directory " + f + " . . .");
    try
    {
    // important to use makedirs for this variant!
    if ((f.mkdirs()) == false)
    {
    System.out.println(
    "Unable to create directory " + directory);
    }
    }
    catch (SecurityException e)
    {
    e.printStackTrace();
    }
    }
    infile.close();
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    }
    }
    </sscce>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
    Andrew Thompson, Oct 8, 2007
    #3
  4. Alan

    Alan Guest

    Andrew,

    What JDK version and operating system were you running this on?

    Thanks, Alan
    Alan, Oct 8, 2007
    #4
  5. Alan

    Alan Guest

    This is bizarre. The following URLs (converted to directory names
    by code above) work, but "www.weather.gov" still does not! This
    happens under Windows Vista, with either Java SE JDK 1.5 or 1.6. It
    does NOT happen under Windows 98SE with JDK 1.5. WTF????

    Anybody have any ideas what is going on? Thanks, Alan

    http://www.brother.com
    http://www.cnn.com
    http://www.weathe.gov
    http://www.weath.gov
    http://www.weat.gov
    http://www.wea.gov
    http://www.we.gov
    http://www.weather1.gov
    http://www.weather12.gov
    http://www.weather123.gov
    http://www.weather1234.gov
    http://www.weather12345.gov
    1234567890
    12345678901
    123456789012
    1234567890123
    12345678901234
    123456789012345
    1234567890123456
    12345678901234567
    123456789012345678
    1234567890123456789
    12345678901234567890
    Alan, Oct 8, 2007
    #5
  6. Alan

    Piotr Kobzda Guest

    Alan wrote:

    > This is bizarre. The following URLs (converted to directory names
    > by code above) work, but "www.weather.gov" still does not!


    As a workaround, try to use "www.nws.noaa.gov" instead. ;-)


    piotr
    Piotr Kobzda, Oct 8, 2007
    #6
  7. Alan

    Alan Guest

    Does anyone else get this same result on Vista?
    Alan, Oct 9, 2007
    #7
  8. Alan

    Alan Guest

    Does anyone else running Windows Vista have this problem?
    Alan, Oct 9, 2007
    #8
  9. Piotr Kobzda wrote:
    >> This is bizarre. The following URLs (converted to directory names
    >> by code above) work, but "www.weather.gov" still does not!

    >
    >As a workaround, try to use "www.nws.noaa.gov" instead. ;-)


    I think that is a good suggestion. Try .gov1 as well.

    To answer an earlier question, I am using 1.6 on XP Pro.

    As far as this problem goes, I have a sneaking suspicion
    it /might/ be tied up with a recent bug that cropped up re
    IE/Vista. That problem, though, affected IE/Vista & trusted
    JWS & applets, Vista being the only one of which seems
    immediately evident here.

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
    Andrew Thompson, Oct 9, 2007
    #9
  10. Alan

    Roedy Green Guest

    On Mon, 08 Oct 2007 18:08:04 -0000, Alan <>
    wrote, quoted or indirectly quoted someone who said :

    > Am I missing something obvious?


    The usual problems are:

    1. the directory already exists.

    2. there is a file already by that name.

    3. you are trying to create a directory when the parent does not yet
    exist. Use mkdirs with an s to create parents automatically.

    Go a have a peek with explorer to see what is going on.
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Oct 9, 2007
    #10
  11. Alan

    Roedy Green Guest

    On Mon, 08 Oct 2007 20:49:41 -0000, Alan <>
    wrote, quoted or indirectly quoted someone who said :

    > This is bizarre. The following URLs (converted to directory names
    >by code above) work, but "www.weather.gov" still does not! This
    >happens under Windows Vista, with either Java SE JDK 1.5 or 1.6. It
    >does NOT happen under Windows 98SE with JDK 1.5. WTF????


    I ran Andrew's code with your list of URLS and all worked fine as
    best as I could tell on Vista home premium .

    I made one small modification. " == false" sets my teeth on edge, and
    corrected a typo in the comment.

    // important to use mkdirs for this variant!
    if ( !f.mkdirs() )
    {
    System.out.println(
    "Unable to create directory " +
    directory);
    }




    http://www.brother.com
    Creating directory cache\com\brother\www . . .
    http://www.cnn.com
    Creating directory cache\com\cnn\www . . .
    http://www.weathe.gov
    Creating directory cache\gov\weathe\www . . .
    http://www.weath.gov
    Creating directory cache\gov\weath\www . . .
    http://www.weat.gov
    Creating directory cache\gov\weat\www . . .
    http://www.wea.gov
    Creating directory cache\gov\wea\www . . .
    http://www.we.gov
    Creating directory cache\gov\we\www . . .
    http://www.weather1.gov
    Creating directory cache\gov\weather1\www . . .
    http://www.weather12.gov
    Creating directory cache\gov\weather12\www . . .
    http://www.weather123.gov
    Creating directory cache\gov\weather123\www . . .
    http://www.weather1234.gov
    Creating directory cache\gov\weather1234\www . . .
    http://www.weather12345.gov
    Creating directory cache\gov\weather12345\www . . .
    1234567890
    Creating directory cache\1234567890 . . .
    12345678901
    Creating directory cache\12345678901 . . .
    123456789012
    Creating directory cache\123456789012 . . .
    1234567890123
    Creating directory cache\1234567890123 . . .
    12345678901234
    Creating directory cache\12345678901234 . . .
    123456789012345
    Creating directory cache\123456789012345 . . .
    1234567890123456
    Creating directory cache\1234567890123456 . . .
    12345678901234567
    Creating directory cache\12345678901234567 . . .
    123456789012345678
    Creating directory cache\123456789012345678 . . .
    1234567890123456789
    Creating directory cache\1234567890123456789 . . .
    12345678901234567890
    Creating directory cache\12345678901234567890 . . .
    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Oct 9, 2007
    #11
  12. Alan

    Alan Guest

    As far as this problem goes, I have a sneaking suspicion
    it /might/ be tied up with a recent bug that cropped up re
    IE/Vista. That problem, though, affected IE/Vista & trusted
    JWS & applets, Vista being the only one of which seems
    immediately evident here.

    Andrew,

    Do you have a web link that describes this problem? With Vista,
    it seems to be: "So many problems, so little time."

    Thanks for mentioning this. I have not found a reference to one
    like this.

    Roedy,
    I watched with Explorer, but I saw nothing unusual there.

    There are workarounds, but it is just perplexing and
    frustrating.
    Thanks, Alan
    Alan, Oct 9, 2007
    #12
  13. Alan wrote:

    (A.T.)
    >As far as this problem goes, I have a sneaking suspicion
    >it /might/ be tied up with a recent bug that cropped up re
    >IE/Vista. That problem, though, affected IE/Vista & trusted
    >JWS & applets, Vista being the only one of which seems
    >immediately evident here.


    Alan
    > Do you have a web link that describes this problem?


    OK, just quickly, it was something to do with
    Vista and files, ..
    <http://www.google.com/search?as_q=vista+file&as_sitesearch=bugs.sun.com>

    This is probably the one.
    "Bug ID: 6548078 The Java Security Model is broken on Windows Vista ..."
    <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6548078>

    --
    Andrew Thompson
    http://www.athompson.info/andrew/

    Message posted via JavaKB.com
    http://www.javakb.com/Uwe/Forums.aspx/java-general/200710/1
    Andrew Thompson, Oct 9, 2007
    #13
  14. Alan

    Alan Guest

    Alan, Oct 9, 2007
    #14
  15. Alan

    Alan Guest

    Well, I found the problem. Windows Vista does not like it when I
    try to make a directory with the same name (without extension) as a
    different type file (e.g., "www.weather.gov" (HTML file) or
    "www.weather.gov (Word file)). Windows 98 does not mind. Vista
    handles extensions differently.


    I found that if I first check to see if the directory already
    exists, and then create it if not, everything works fine! So,
    something screwy in JDK on Vista must be happening when I try
    "mkdirs()" without checking the existence first. Odd. . . .

    Alan
    Alan, Oct 10, 2007
    #15
  16. Alan

    Lew Guest

    Alan wrote:
    > Well, I found the problem. Windows Vista does not like it when I
    > try to make a directory with the same name (without extension) as a
    > different type file (e.g., "www.weather.gov" (HTML file) or
    > "www.weather.gov (Word file)). Windows 98 does not mind. Vista
    > handles extensions differently.


    Comparing anything to how Win 98 works is pretty amusing.

    --
    Lew
    Lew, Oct 11, 2007
    #16
  17. Alan

    Roedy Green Guest

    On Wed, 10 Oct 2007 18:28:52 -0000, Alan <>
    wrote, quoted or indirectly quoted someone who said :

    > I found that if I first check to see if the directory already
    >exists, and then create it if not, everything works fine! So,
    >something screwy in JDK on Vista must be happening when I try
    >"mkdirs()" without checking the existence first. Odd. . . .


    mkdirs takes a while to do its job. If you check existence afterward,
    you might not see its result. That may have some bearing on this
    strange behaviour.

    --
    Roedy Green Canadian Mind Products
    The Java Glossary
    http://mindprod.com
    Roedy Green, Oct 11, 2007
    #17
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon
    Replies:
    2
    Views:
    620
    Jon R
    Nov 12, 2003
  2. =?Utf-8?B?U2l2YXJhbWFuLlM=?=

    Unable to create new users using Directory services in Windows 200

    =?Utf-8?B?U2l2YXJhbWFuLlM=?=, Jan 19, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    433
    David Jessee
    Jan 20, 2005
  3. SampathTangudu
    Replies:
    0
    Views:
    2,625
    SampathTangudu
    Jan 28, 2005
  4. Sivaraman.S
    Replies:
    1
    Views:
    136
    Joe Kaplan \(MVP - ADSI\)
    Jan 19, 2005
  5. Jake Barnes
    Replies:
    6
    Views:
    390
    9.co.uk
    Feb 8, 2006
Loading...

Share This Page