How do I Get User Application Data Directory in Java?

The Java program sometimes need to access the user application data directory, to save or get some temp or cache dates, the application data file path is defined as following:

Window XP or 2003:

C:\Documents and Settings\$USER$\Local Settings\Application Data

Windows Vista:

C:\Users\$USER$\AppData\Roaming

This directory is a special Windows folder, notice $USER$ specific logged username on current computer, by default the Application Data dir is hidden status.

1. Get user application data directory:

1
String dataFolder = System.getProperty("user.home") + "\\Local Settings\\Application Data";

2. Get it in file pattern:

1
File appData = new File(System.getProperty("user.home"), "\\Local Settings\\Application Data ");

A more simply way:

1
String dataFolder = System.getenv("APPDATA");
Rate article
ASJAVA.COM
Add a comment

Your email address will not be published. Required fields are marked *

  1. Claudio

    Unfortunately 1 and 2 works only for English versions of Windows.

    And the third seems not to work for all Windows versions.

    Reply