Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 677
Ky. Avatar asked Feb 10 '12 22:02

Ky.


2 Answers

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.

like image 41
a_horse_with_no_name Avatar answered Oct 06 '22 22:10

a_horse_with_no_name


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

like image 64
IceMan Avatar answered Oct 06 '22 21:10

IceMan