如何获取Java中Windows的%APPDATA%位置变量的值? [英] How do I get the value of Windows' %APPDATA% location variable in Java?

查看:282
本文介绍了如何获取Java中Windows的%APPDATA%位置变量的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使程序在用户使用Windows时将其状态保存在%APPDATA%设置的位置。但是, System.getProperty( temp.dir); 不会返回该值。 如何在Windows中获取%APPDATA%变量的值,以保存状态?

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?

推荐答案

使用System.getenv()

Use System.getenv()

System.getenv("APPDATA")

但我认为

System.getProperty("user.home") 

即使它不是完全相同的东西,也应该首选它,因为它更便于携带。

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

这篇关于如何获取Java中Windows的%APPDATA%位置变量的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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