Saving Game to Program Files.

Hey Everyone,

Maybe someone could help me. How would i go about creating a new folder in my program files in java ? does anyone know the best way to do this ?

Thanks

  • GlennBrann

I am not 100% sure if I understand this correctly.

Do you want to install your game to _:\Program Files\yourGame\

or do you just want to create some _:\Program Files\someFolderForSavesOrWhatever\ whenever you run your java game(regardless of where its located?)

I want to [quote] want to create some _:\Program Files\someFolderForSavesOrWhatever\ whenever you run your java game(regardless of where its located?)
[/quote]
How would i do this ?

That folder is generally for actual program files. Typically game saves and some config files are saved in:

My Documents/
Saved Games/
AppData/Local/…

or something like that, which has different permissions than Program Files, so the program can actually use all the files.

As for actually saving to it, all you need to do is find the folder on the machine, and from there it’s however you prefer to do your file IO.

Most commonly, you’ll find it in :\Users<Username>\My Documents. If you are bent on Program Files, that’s
:\Program Files.

So! What you need to do is look up how to find the Operating system’s drive letter, and from there it’s simple.

Don’t hard code absolute paths. You can get the user/home directory at run time.

You don’t want to create files and folders in odd places in your user’s computer. I’d be furious if anything was saved anywhere else but from the executables/jars own folder or somewhere non-obtrusive in MyDocuments.

Ok guys, Thanks for the advice. Ill just stick to keeping it in the same folder.

  • GlennBrann