Solved

Somewhere to save....

Posted on 2004-09-03
6
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

726 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