Re: Current Class Path

From: David Postill (david_at_postill.org.uk)
Date: 10/29/03


Date: Wed, 29 Oct 2003 17:56:18 GMT


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In article <b735eace.0310290822.76cf4fe3@posting.google.com>, on 29 Oct 2003 08:22:48 -0800, betch23@hotmail.com (RB)
wrote:

| We are trying to get the current class path of our Java program which
| is installed to c:\program files\my program\. In case the path
| changes, we need to get the new path. Everytime we use the
| java.lang.System.getProperty("user.dir"), we get the jdk directory
| path opposed to our program path.
|
| Could anyone tell me how to get the class path and not the jdk path?

Hmm. Not sure exactly what you are trying to do from your description.

Are you trying to get the current working directory?

Try this code and see if it works for you.

  /**
   * Returns a string consisting of the current working directory.
   *
   * @since JToolkit 0.2
   */

  public static String getCWD()
    {
    // [idea courtesy of <a href="mailto:travis@nrg.org.invalid">Travis Thornhill</a>]

    File file;
    int index;
    String pathSeparator;
    String cwd = null;

    file = new File( "." );
    pathSeparator = File.separator;
    index = file.getAbsolutePath().lastIndexOf( pathSeparator );

    try
      {
      cwd = file.getAbsolutePath().substring( 0, index );
      }
    catch ( StringIndexOutOfBoundsException e )
      {
      System.err.println( "Caught Exception: " + e.getMessage() + "\n" );
      }

    return cwd;
    }

Regards,

<davidp />

- --
David Postill

-----BEGIN PGP SIGNATURE-----
Version: PGP 8.0.3 - not licensed for commercial use: www.pgp.com
Comment: Get key from pgpkeys.mit.edu:11370

iQA/AwUBP5/wUnxp7q1nhFwUEQIO+wCfeD2bCbSQrH9qrDcy+8coP05BKAkAniK1
vbbSAOXsT/MlVllsw2xxdIjx
=BBnJ
-----END PGP SIGNATURE-----



Relevant Pages

  • RfD: Directories
    ... How do I refer to another file that is distributed with the ... The source file of the string is important for the expansion, ... where the consumer is not in the same file as the string); ... current working directory (unfortunately not the directory containing ...
    (comp.lang.forth)
  • Re: Logging off
    ... public static Process RunExecutable(string exe, string userName, string password) ... // So will set the working directory to the current directory. ... The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ASP.Net problem with process.start
    ... public static string StartProcessAndGetOutput( ... string fileName, ... allow me to specify if the working directory is the filename directory. ... SB> I've build a custom web service that is used to digitally signed cab ...
    (microsoft.public.dotnet.framework)
  • Re: call of ShellExecuteEx causes error message
    ... My Java program brings up its own window and is for drawing curves, ... //define pix vector from Photoshop image ... //make string from pix vector ... the call of ShellExecuteEx worked. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Scheduled Task .JOB-file executable name
    ... If the second part does not exist, there are four zero ... >and the string would follow as two-byte Unicode characters in bytes ... This first part of the scheduled task ... >the working directory followed by the ...
    (microsoft.public.scripting.vbscript)