There are different ways to do that:
- You can write to a
FileHandle
. Just create a FileHandle
like Gdx.files.local("myfile.txt");
and write to it using fileHandle.writeString(Integer.toString(myInt));
Note, that Internal
and Classpath
are read-only, so you can't write files there.
Also note, that not all types of the gdx.files.
are usable for all backends. More on that here.
The second way to do that are the Preferences. The Preferences
are the only way to have persistent data for HTML5 applications.
The Preferences
are XML files in which you can store, read and change data.
To create Preferences
for your app you just need to call:
Preferences myPref = Gdx.app.getPreferences("PreferenceName");
Note, that you should use the full name, for example com.stackoverflow.preferences
, as on desktop all Preferences
use the same file.
To write data you can use myPref.putInteger("name", value)
for Integer
s, myPref.putBoolean(("name", value)
for Boolean
s... Make sure you call myPref.flush()
after all changes, to save the new data.
To get the data you can call myPref.getInteger("name, defaultValue")
. The default value is returned if there is no data with the given name.
More on Preferences
here.
Hope i could help.