Solved

Somewhere to save....

Posted on 2004-09-03
6
206 Views
Last Modified: 2010-03-31
Hi all,
       I need to write a config file to an easy to find place. i first thought to just use c:\ but then remembered that my other machine doesn't have c: but f:  instead ( go figure ). anyway what i  was wondering was whether or not there is an easy way to find the system drive from Java?
0
Comment
Question by:petepalmer
  • 3
  • 2
6 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 125 total points
ID: 11972126
>>I need to write a config file to an easy to find place
Why not use the user's home directory?

System.getProperty("user.home");
0
 
LVL 37

Expert Comment

by:zzynx
ID: 11972142
On Windows e.g. that will return

     C:\Documents and Settings\<userid>

The drive is the system drive
0
 
LVL 1

Author Comment

by:petepalmer
ID: 11972155
That will do very nicely thank you :)
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 37

Expert Comment

by:zzynx
ID: 11972188
You're welcome.
Thanks for accepting
:°)
0
 
LVL 1

Expert Comment

by:primusmagestri
ID: 11972206
I like to keep my jars, config files and starter batch files in (almost) the same place. This code gives you the jar file path:

     String path;
     try
        {

            String className = getClass(  ).getName(  );
            className = className.substring( className.lastIndexOf( '.' ) + 1 )
                        + ".class";

            path = getClass(  ).getResource( className ).getPath(  );
            path = URLDecoder.decode( path, "UTF-8" );

            int pos = path.substring( 0, path.indexOf( '!' ) ).lastIndexOf( '/' );
            path = path.substring( path.indexOf( '/' ) + 1, pos );
            if( System.getProperty( "file.separator" ).equals( "/" ) )
            {
                //include "/" at start for UNIX OS
                path = "/" + path;
            }
        }
        catch( Exception ex )
        {
            System.out.println( "Could not init application paths; " + ex.getMessage(  ) );
        }
0
 
LVL 1

Expert Comment

by:primusmagestri
ID: 11972213
Wow, that was fast...
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now