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:


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:

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

2. Get it in file pattern:

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

A more simply way:

String dataFolder = System.getenv("APPDATA");
Оцените статью
Добавить комментарий

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.