Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图让我的程序将其状态保存%APPDATA%在用户使用 Windows 时设置的位置。但是,System.getProperty("temp.dir");不返回那个。为了保存状态,如何%APPDATA%在 Windows 中获取变量的值?
%APPDATA%
System.getProperty("temp.dir");
使用 System.getenv()
System.getenv("APPDATA")
但我认为
System.getProperty("user.home")
应该首选,即使它不完全相同,因为它更便携。
APPDATA 是一个特定于 Windows 的环境变量,它为您提供存储应用程序特定数据的位置,因此如果您不想编写独立于平台的代码,您可以这样做System.getenv("APPDATA");
System.getenv("APPDATA");