Results 1 to 8 of 8
  1. #1
    KingdomHeart is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default create a folder in MAC

    It return false when I try to create the folder "test" in the $home directory
    Java Code:
            File f = new File("~/test");
            if(!f.exists()){
                if(f.mkdir()){
                    System.out.println("Successful");
                }
            }

  2. #2
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    5

    Default

    I don't have a MAC, so I can't test, but I ran the code with a Windows path and it works fine.

    Try adding a "/" at the end, it might help.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  3. #3
    KingdomHeart is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    I will just go ahead and answer m own question. Instead of using the "~" to specify the home directory, use this
    Java Code:
    System.getProperty("user.home");

  4. #4
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    5

    Default

    to lazy to open netbeans but I am sure you can somehow track that error down, gonna watch tomorow

  5. #5
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    5

    Default

    Quote Originally Posted by KingdomHeart View Post
    I will just go ahead and answer m own question. Instead of using the "~" to specify the home directory, use this
    Java Code:
    System.getProperty("user.home");
    So, is that different than "~" (on a mac) or what? I'm not familiar with Mac file notation, just windows and a bit of UNIX.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  6. #6
    KingdomHeart is offline Member
    Join Date
    Nov 2009
    Posts
    3
    Rep Power
    0

    Default

    I think:
    ~ : $home that recognize by the shell
    System.getProperty("user.home") : $home that recognize by java

    that what I think, feel free to correct me if I am wrong

  7. #7
    CodesAway's Avatar
    CodesAway is offline Senior Member
    Join Date
    Sep 2009
    Location
    Texas
    Posts
    238
    Rep Power
    5

    Default

    Quote Originally Posted by KingdomHeart View Post
    I think:
    ~ : $home that recognize by the shell
    System.getProperty("user.home") : $home that recognize by java

    that what I think, feel free to correct me if I am wrong
    Oh, makes sense. I know the latter is Java's way to keep everything platform independent.

    Similarly, you should use File.separator instead of "/" in your paths, so that the same code works on the different OSes.
    CodesAway - codesaway.info
    writing tools that make writing code a little easier

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,949
    Rep Power
    19

    Default

    Quote Originally Posted by KingdomHeart View Post
    I think:
    ~ : $home that recognize by the shell
    System.getProperty("user.home") : $home that recognize by java

    that what I think, feel free to correct me if I am wrong
    And that's why it doesn't work, since Java isn't in a shell. It's a shell-specific shortcut.

Similar Threads

  1. code to create a folder in java
    By radhika123 in forum New To Java
    Replies: 7
    Last Post: 07-21-2011, 11:21 AM
  2. create gui browse folder destination
    By gisler in forum AWT / Swing
    Replies: 1
    Last Post: 11-22-2009, 04:13 PM
  3. Create a folder within a java program.
    By yellowfire7 in forum New To Java
    Replies: 2
    Last Post: 10-26-2009, 10:14 PM
  4. How to create Folder View
    By jazz2k8 in forum Advanced Java
    Replies: 2
    Last Post: 10-24-2008, 02:04 PM
  5. How to create folder(s) and store data?
    By Grom in forum New To Java
    Replies: 2
    Last Post: 08-20-2008, 09:01 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •