Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what is System.getProperty("user.home") output in windows? [closed]

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.

like image 229
Anti Atlas Dev Avatar asked Feb 12 '17 04:02

Anti Atlas Dev


People also ask

What is the value returned by system getProperty user home?

The getProperty method returns a string containing the value of the property. If the property does not exist, this version of getProperty returns null.

What is the use of system getProperty user dir?

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.

Why do we use system getProperty?

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.

What is user home in Java?

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.


2 Answers

It will be the home directory of the current logged in user. c:\Users\${current_user_name}

like image 82
DNAj Avatar answered Oct 21 '22 07:10

DNAj


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。

like image 27
lpgad Avatar answered Oct 21 '22 07:10

lpgad