Question

So, I'm creating a game and need to create directories to store all the user's data and saves and whatnot. As you can see, I need to create a folder in the Application Data folder of the user called, "[WarDungeon]", and there, I will store other folders for such data like levels, the bin, sprites, etc.

I am not too interested in working with Mac OS and Linux as I want to get the %appdata% folder working with Windows to begin with.

Here's my code:

public FileManage() {
    gamePath  = System.getenv("APPDATA") + "[WarDungeon]";
    gameLevelPath  = System.getProperty("user.home") + "\\Local Settings\\ApplicationData\\[WarDungeon]\\level";
    gameBinPath  = System.getProperty("user.home") + "\\Local Settings\\ApplicationData\\[WarDungeon]\\bin";

    File createDir1 = new File(gamePath);
    createDir1.mkdir();

    System.out.println("First test passed.");

    if (createDir1.exists() == true) {
        System.out.println("First directory created!");
    }
}

How do I fix this?

Thanks in advance, :)

Was it helpful?

Solution 2

Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

OTHER TIPS

I realize that this question is two years old, but since this is the first result while googling "java store in appdata", I decided to add a correct answer for future googlers.

The question is tagged with Java, and the OP posted Java code, but the accepted answer is .NET (not Java).

Quoted directly from this answer:

System.getenv("APPDATA")

This will give the location to the user's AppData folder (in Windows). You can get a result similar to what the OP wanted by doing the following:

File characterFolder = new File(System.getenv("APPDATA") + "\\" + characterName);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top