Results 1 to 6 of 6

Thread: Paths

  1. #1
    N00Bie is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default Paths

    Hey!

    Was reading some online tuts and best practices and it says do not save direct file to paths like this:
    Java Code:
    ImageIcon imageBack = new ImageIcon("C:\\Users\\RyanFuji\\workspace\\Ryan\\src\\Capture.png");
    
    
    or 
    
    
    setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\RyanFuji\\workspace\\Ryan\\src\\MU-Red-icon.png"));
    because when you distribute your programs the other person (rightfully) wont have the files in the same path.

    Unfortunately it does not say HOW to do it instead.

    Doing a search on google for paths and files as you can imagine gives me mostly class paths and java.io :rolleyes:

    How to do this so it works everywhere?

  2. #2
    dinosoep is offline Senior Member
    Join Date
    Nov 2009
    Posts
    150
    Rep Power
    6

    Default

    save to the curent location of the program and to the curent user's home dir

  3. #3
    N00Bie is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Quote Originally Posted by dinosoep View Post
    save to the curent location of the program and to the curent user's home dir
    While that makes sense, I'm a total newb and would appreciate some code to show me how that is done, please.

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,763
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by N00Bie View Post
    While that makes sense, I'm a total newb and would appreciate some code to show me how that is done, please.
    Check the "user.home" property value in the System.getProperty( ... ) set of properties. It's a directory and you can construct a subdirectory from there where you can store and find your images.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

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

    Default

    "user.home" often makes sense as has been noted previously.

    Sometimes it makes sense for an application to save data to some specific location. This could be decided on by the user, or for multiple users it might have to be set by an administrator who can assign the appropriate rights etc. Moreover the data location is just a special case of general properties that may need to be set which could be anything: locale, default font size etc.


    For tools that help with the general case, have a read of The Platform Environment in Oracle's Tutorial. System properties can also be set when the program is launched using the -D option of the java executable.

  6. #6
    N00Bie is offline Senior Member
    Join Date
    Feb 2011
    Posts
    107
    Rep Power
    0

    Default

    Thanks guys! Am off to Google based on your help... feel free to leave additional advise if you want.

Similar Threads

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