Solved

Somewhere to save....

Posted on 2004-09-03
6
208 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
splitOdd10 challenge 5 108
table example 4 29
iterator/ListIterator approach 17 28
Glassfish admin console not working 1 16
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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

832 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