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
2009-11-04 07:11:53
Thanks VonC.. I got the expected Result.. Thank you and thanks for all..
i2ijeya
2009-11-04 07:13:57
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
2009-11-10 09:12:13
+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
2009-11-04 07:12:16