简体   繁体   English

Java认为我的主文件夹是C盘吗?

[英]Java thinks my home folder is the C drive?

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\\... 以前,它曾经返回过类似C:\\Users\\...

Is there a configuration file I need to clear? 是否需要清除配置文件?

When you invokes the “ System.getProperty("user.home"); 当您调用“ 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. 在您的代码中,“ JVM”不会使用Windows环境变量来确定用户配置文件的位置,而是访问引用用户桌面目录的注册表项。 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. 因此,请检查HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\中您的桌面目录的注册表项,并进行相应的更新。 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"); 如果您的桌面目录的注册密钥的值为“ C:\\\\ ”,那么在您调用“ System.getProperty("user.home"); ,JVM将返回值“ C:\\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"); 例如,如果您可以将注册表中的桌面密钥Entery修改为“ C:\\Users\\YourName\\Desktop ”,则在调用“ System.getProperty("user.home");将获得“ C:\\Users\\YourNameSystem.getProperty("user.home"); ” in your code. 在您的代码中。

Thank you! 谢谢!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM