Java认为我的主文件夹是C盘? [英] Java thinks my home folder is the C drive?

查看:192
本文介绍了Java认为我的主文件夹是C盘?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

出于某种原因,我必须更改某些配置或其他内容,因为在一个全新的项目中,我输入了这个:

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));

并获得以下输出:

C:\

以前它曾用过返回类似 C:\ Users \ ...

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

是否需要清除配置文件?

Is there a configuration file I need to clear?

推荐答案

当你调用 System.getProperty(user.home); 在您的代码中,JVM不使用Windows环境变量来确定用户配置文件的位置,而是访问引用用户桌面目录的注册表项。然后它获取桌面的父目录并假定它是用户的配置文件目录。因此,请在 HKEY_CURRENT_USER \Software \ Microoft \ Windows \ CurrentVersion \Explorer \ Shell文件夹\ &中查看桌面目录的注册表项。相应地更新它。如果Desktop目录的registery密钥值为 C:\\ ,则JVM返回值 C:\ 当您在代码中调用 System.getProperty(user.home); 时。例如,如果您可以将注册表中的桌面密钥输入修改为 C:\ Users \YourName \Desktop ,您将获得 C:\ Users \YourName 在您的代码中调用 System.getProperty(user.home); 时。

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.

谢谢!

这篇关于Java认为我的主文件夹是C盘?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆