I am programming in Java under a Linux environment and the output of
System.getProperty("user.home")
is
"/home/user/"
What would be the result if I were on windows? I do not have access to a machine running Windows.
The getProperty method returns a string containing the value of the property. If the property does not exist, this version of getProperty returns null.
getProperty() is used to obtain the system property. This system property is specified by the key which is the parameter for the method. To obtain the current working directory, the key used is user. dir.
getProperty() The Java platform uses a Properties object to provide information about the local system and configuration and we call it System Properties. System Properties include information such as the current user, the current version of the Java runtime, and file path-name separator. System.
The System class in Java has a Properties object used to store different properties and configurations of the current working environment. It also holds the user's home directory. We can access these properties by using the getProperty() method of this class.
It will be the home directory of the current logged in user. c:\Users\${current_user_name}
I think you can try it.
public class Demo
{
public static void main(String args[])
{
String demo = System.getProperty("user.home");
System.out.println(demo);
}
}
then result:
C:\Users\bianqi\Desktop\computer>javac Demo.jav
C:\Users\bianqi\Desktop\computer>java Demo
C:\Users\bianqi
You can see the current user under that user group。
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With