How do I get the value of Windows' %APPDATA% location variable in Java?

╄→尐↘猪︶ㄣ 提交于 2019-12-01 00:11:13

问题


I'm trying to make my program save its state in the location set by %APPDATA% when the user is using Windows. However, System.getProperty("temp.dir"); does not return that. How do I get the value of the %APPDATA% variable in Windows, for the purpose of state saving?


回答1:


Use System.getenv()

System.getenv("APPDATA")

But I think

System.getProperty("user.home") 

should be preferred even though it's not exactly the same thing because it is more portable.




回答2:


APPDATA is a Windows specific environment variable that gives you the location where application specific data is stored, so if you are not looking to write platform independent code, you can just do System.getenv("APPDATA");



来源:https://stackoverflow.com/questions/9235734/how-do-i-get-the-value-of-windows-appdata-location-variable-in-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!