2

For some reason, I must have changed some configuration or something, because, in a brand new project, I am entering this:

System.out.println(System.getProperty("user.home"));

and getting the following output:

C:\

Whereas before, it used to return something like C:\Users\...

Is there a configuration file I need to clear?

pb2q
  • 58,613
  • 19
  • 146
  • 147
Redandwhite
  • 2,529
  • 4
  • 25
  • 43

1 Answers1

7

When you invokes the “System.getProperty("user.home");” in your code, the JVM does not use the Windows environment variable to determine the location of the user’s profile, but instead access the registry key that references the user’s desktop directory. It then takes the parent directory of the desktop and assumes that is the user’s profile directory. So please check the registry entry of your Desktop directory in HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\ & update it accordingly. If the value of registery key for your Desktop directory is “C:\\”, the JVM returns the value “C:\” while you invokes “System.getProperty("user.home");” in your code. For example if you could modify the Desktop key entery in the registery to “C:\Users\YourName\Desktop”, you will get “C:\Users\YourName” while invoking the “System.getProperty("user.home");” in your code.

Thank you!

1218985
  • 7,531
  • 2
  • 25
  • 31
  • 2
    It should also be noted that this logic is wrong - there's no guarantee that the parent of the desktop folder is a sensible place. It might not even belong to the user, e.g., if the desktop folder is something like `\\fileserver\desktops\alice`. So it is probably best to avoid using the `user.home` property altogether. – Harry Johnston Oct 02 '12 at 21:29