Solved

Somewhere to save....

Posted on 2004-09-03
6
207 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Application launch issue with Apache Tomcat 5 19
Modeling a class in java 5 46
Saving Tweets with emojis using Twitter4J in a Mysql table 2 73
Starting to learn JAVA, 7 59
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

919 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

21 Experts available now in Live!

Get 1:1 Help Now