Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default Paths in different os's

    Hi. I have some code that decides the os of the user, then uses a different path to find a file according to that. here is the code so far:
    Java Code:
    String os = System.getProperty("os.name").toLowerCase();
    String path;
    
    if(os.indexOf( "win" ) >= 0){
    	path =
    }else if(os.indexOf( "mac" ) >= 0){
    	path = "/Applications/Program.jar";
    }else if(os.indexOf( "nix") >=0 || os.indexOf( "nux") >=0){
    	path =
    }
    as you can see, I dont have the paths in for windows or linux. I have a mac so I don't know the paths. All I need is for someone to give me the paths to the folder containing applications on windows and linux. Thanks in advance!
    Last edited by hardcorebadger; 01-27-2011 at 11:41 PM. Reason: wrong code

  2. #2
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    I also need runtime commands for the different operating systems, on mac I do:
    Java Code:
    Runtime rt = Runtime.getRuntime();
    rt.exec("java -jar " + path);

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Neither Windows nor *nix have a notion of program directory. By tradition *nix executables are put in a number of places (depending, eg, on whether they are for the root user, shared between users, local to a specific user), Windows is only dimly aware of multiple users.

    Both these operating systems have a notion of "path": but there is no reason to suppose that all or only executables lie on the path. But you could try SYstem.getEnv("path") which returns a string)

    As far as runtime commands are concerned you might want to read the famous JavaWorld When Runtime.exec() won't article.
    Last edited by pbrockway2; 01-28-2011 at 12:28 AM.

  4. #4
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    well its not that i NEED a folder with solely applications, I just need a place that is default on that os and people can put my jar file. like documents etc. Just tell me where you would have users place the jar for each os.

  5. #5
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,785
    Rep Power
    7

    Default

    A user can "install" a program anywhere they choose. How are you going to handle it if you hard code a path when the jar file has been placed somewhere else by the user?

  6. #6
    gcalvin is offline Senior Member
    Join Date
    Mar 2010
    Posts
    953
    Rep Power
    5

    Default

    Just joining the chorus to say this is a really bad idea. Even on a Mac, there's no guarantee that your program will be in /Applications. Are you wanting this to help you build an installer, or is this for runtime?

    -Gary-

  7. #7
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    There is a read me that tells the user where to put the file, I'm not guessing that the file is in /Applications, I'm telling them to put it there. I just don't even remotely know paths on other os's. I'm just asking for someone to give me a path, then it'll be in the read me to put the jar in that folder. Nothing to do with guessing where it is.

  8. #8
    Join Date
    Jan 2011
    Posts
    30
    Rep Power
    0

    Default

    In the end it's for runtime, which I don't know even works on other os's

Similar Threads

  1. Getting User name for paths
    By xael in forum New To Java
    Replies: 3
    Last Post: 09-09-2010, 09:25 AM
  2. getting paths and directories
    By marco in forum Java Applets
    Replies: 3
    Last Post: 11-25-2007, 07:28 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
  •