How to get path to special system directories using Java
How to extract the path "c:/documents and settings/user" usin开发者_开发问答g Java... Is there any method??
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
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.
精彩评论