CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 1999
    Posts
    1

    getCodeBase() equivalent for application?

    Hi:

    Is there an equivalent form of getCodeBase() I can use in an application to find the directory the application is running from?

    Thanks,

    Derek


  2. #2
    Join Date
    Apr 1999
    Posts
    4

    Re: getCodeBase() equivalent for application?

    Try
    public static Properties getProperties().

    It should provide you with a set of properties consisting of for example:
    java.version
    java.vendor
    java.home (java installation directory)
    java.class.path (could come in handy for you)
    os.name
    os.version
    user.name (user account name!)
    user.home (user's home directory)
    user.dir (user's current working directory.
    Probably what you're looking for)



  3. #3
    Guest

    Re: getCodeBase() equivalent for application?

    Yep, there's a way:

    String classDirectory = getClass().getResource("ClassName.class").toString();


    This line of code gives you the string representation of the directory where the class is.

    Hope that helps.
    Matty


  4. #4
    Guest

    Re: getCodeBase() equivalent for application?

    When I use the following:


    t = new Test();
    String classDirectory = t.getClass().getResource("Test.class").toString();




    I get 'systemresource:/FILE0/+/com/xxx/yyy/Test.class' (without the quotes) ? What does /FILE0/+/ mean ? I was expecting drive and directory info (Window NT)?


  5. #5
    Join Date
    Sep 1999
    Location
    Madurai , TamilNadu , INDIA
    Posts
    1,024

    Re: getCodeBase() equivalent for application?


    One simple solution is :



    public String getClassDirectory() throws IOException {
    File f = new File(".");
    return f.getCanonicalPath();
    }






Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured