Results 1 to 3 of 3
  1. #1
    IYIaster is offline Member
    Join Date
    Jul 2009
    Rep Power

    Default Get application directory

    Trying to get application directory. I've tried a couple of different ways to get the applications directory.

    This one returns the current directory so if I have a desktop shortcut to the jar file it returns curDir = path/to/desktop
    Java Code:
    String curDir = System.getProperty("user.dir");
    When running this code from CMD it doesn't return anything.
    Java Code:
    URL mySource = Main.class.getProtectionDomain().getCodeSource().getLocation();
    File sourceFile = new File(mySource.getPath());
    Is there an easy way to get the applications directory?

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Rep Power


    The second one is the way to do it. How are you determining that it "isn't returning anything".

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Colombo, Sri Lanka
    Blog Entries
    Rep Power


    I vote for the second way as well, and how did you confirm that's not returning anything. I'm confusing on what you said as well. How you work around with the File object?

Similar Threads

  1. JDK Directory
    By PhQ in forum Eclipse
    Replies: 1
    Last Post: 03-21-2010, 04:54 AM
  2. Directory Structure
    By rummy in forum New To Java
    Replies: 1
    Last Post: 01-21-2010, 01:03 PM
  3. How to. Files and Directory
    By ocean in forum New To Java
    Replies: 4
    Last Post: 12-06-2009, 07:23 PM
  4. Replies: 3
    Last Post: 12-04-2009, 01:10 PM
  5. working directory in web application
    By Juuno in forum Advanced Java
    Replies: 1
    Last Post: 05-04-2009, 07:45 PM

Posting Permissions

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