0

Heyo,

I'm coming from VB.Net, so I'm pretty spoiled when it comes to accessing the Windows OS and shiz like that.

Now, I'd like to create a settings file for my program which will be saved in the user's documents directory (C:\Users\XXYY\My Documents\MyProgram\MySettingsFile.file).

In VB, I'd do something like this:

Private docs As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
If Not File.Exists(docs & "\My Program\MySettingsFile.file") Then
    File.Create(docs & "\My Program\MySettingsFile.file")
    Return FileExists
Else
    Return FileDoesntExist
End If

How would I achieve such a thing in Java? I don't necessarily mean the FileIO bit, that's rather easy, but I meant the documents thing. I know it's possible from playing Minecraft, which saves its files in the AppData\Roaming part of the Windows profile.

Any help is much appreciated!

Thanks in advance.

SimonC
  • 1,547
  • 1
  • 19
  • 43

2 Answers2

3

In java you can use

System.getProperty("user.home")

That will give you the path to the current users home directory.

http://docs.oracle.com/javase/tutorial/essential/environment/sysprop.html

CamHart
  • 3,825
  • 7
  • 33
  • 69
1

Are you looking for this?

System.getenv("APPDATA");