0

I am trying to develop a little game in Libgdx/Java :) But before i implement a save system, i got some questions about it :

I often see, no i always see that games stores there game variables in files. And i already know how to save my data into an xml file ... which looks so :

<?xml version="1.0" encoding="UTF-8"?>
<Word>Hello</Word>

But is that efficient ? Or are there better methods to save data in files ? And is it worth to store data in files? An other little question is, how do i load that stuff out of this file above there? And example, if i wanna load the Word "Hello" into an String ... how do i do that?

I found some interesting posts but they didn't work, maybe they are outdated :/

Heres one : Java: How to read and write xml files?

Community
  • 1
  • 1
genaray
  • 1,080
  • 1
  • 9
  • 30
  • dont use DOM since it is takes too much memory to build the tree structure if the source xml is large, have a look here for more efficient ways: http://stackoverflow.com/questions/373833/best-xml-parser-for-java?rq=1 – riteshtch Feb 16 '16 at 17:41
  • Ok thanks :) What about XStream ? I think its easy to create xml files with it ... but you cant load data – genaray Feb 16 '16 at 17:43
  • for streamed reading you can use `woodstox` which is a `stax` parser and has considerable num of efficiency configurations, and yeah those are auto serialization/deserialization libraries are easier and efficient to use, as far as my googling says `xstream` does have loading facility http://tomaszdziurko.pl/2013/04/xstream-xstreamely-easy-work-xml-data-java/, i'd also suggest to use `xstream` or any other lib such as `gson` and have the underlying source as `json`, `json` being lightweight wrt `xml` http://stackoverflow.com/questions/12346349/why-is-json-more-lightweight-than-xml – riteshtch Feb 16 '16 at 17:48
  • You actually *can* [load data from XStream](http://x-stream.github.io/tutorial.html) (see the section Deserializing an object back from XML ) – OneCricketeer Feb 16 '16 at 21:22

1 Answers1

0

You could use Preferences:

    Preferences prefs = Gdx.app.getPreferences("My Preferences");
    prefs.putString("name", "Donald Duck");
    String name = prefs.getString("name", "No name stored");

    prefs.putBoolean("soundOn", true);
    prefs.putInteger("highscore", 10);

Found it here: https://github.com/libgdx/libgdx/wiki/Preferences