tags:

views:

76

answers:

2

How to extract the path "c:/documents and settings/user" using Java... Is there any method??

+6  A: 
System.getProperty("user.home")

should be enough. See here for an example.

public class UserHomeExample 
{
    public static void main(String[] args)
    {

        System.out.println("User Home Path: "+ System.getProperty("user.home"));
    }
}

Gives:

C:\convert\rajesh\completed>javac UserHomeExample.java

C:\convert\rajesh\completed>java UserHomeExample
User Home Path: C:\Documents and Settings\Administrator
VonC
Thanks VonC.. I got the expected Result.. Thank you and thanks for all..
i2ijeya
VonC Can we also get current file path (i.e) from the above example can i get the info where UserHomeExamble.class is stored ?
Hari
+3  A: 

The user's home directory is exposed by the JVM as a System property. You can retrieve it (as a String) using this method:

String homeDirectory = System.getProperty("user.home");

If you want the parent directory for all users (as you indicate in the question), just append /.. to this.

Chris R