Alright so this might sound really stupid but i am making a text based rpg in java because i like making them anyways my friend was telling me that you can make a simple save so that it saves all the variables into a text file. so what im asking is how do you do this i have literally no clue on were to start. if at al possible could someone maybe post a source code on for like a window hat pops up and you can select that text file and then load the variables that you previously saved. remember i have never done anything like saving so please if you can maybe put some comments in that would tell me what some parts of the code are doing if you decide to help me. many thanks to all that help 
ok, basicly google this “file IO in java”. if you havent got the idea yet here it is.
you make a file that is named the name of the user(or the username). then in there you write wateva you want in there. so like your health, mana, level, exp, money, items, skills. and then when you load it. jsut read the file, and go ok line 1 is health, line 2 is mana.
I havent done this in java. I have done this in basic, the same concept should apply.
it may be more efficient to have a file called username+“skills”, and username+“inventory” and so on.
but only do this with the stuff that there si a lot of.
GL with the game
Abuse was faster, anyway:
There are multiple options to do this. A common way is to use Properties, where you need to put in the values.
Another option would be Serialization, which is a bit more comfortable, since you don’t have to convert your variables from and to a string representation. On the downside, the written files normally aren’t human readable.
If your class containing the variables follow java bean pattern (having public getter and setter methods), you can use Bean XML Serialization, which produces a human readable xml file. If you don’t want to bother and are willing to use a third party library, you can use XStream, which allows very easy persistance of arbitrary java objects to xml files. Under more complex circumstances you might save your whole memory, though 
There is also the Java Architexture for XML Binding, but this may be a bit of an overkill…
Now what’s funny about that is the multiple of 10 line numbering.
Reminds me of learning Basic on my good old speccy.
Haha, I hadn’t noticed that!
me too.
I have not done any file saving in java.
Is this way easier/better than mine?
causee if so thanks for saving me a hassle later.
It’s just a matter of time until we can use complex numbers there.
goto with volumetric jumps. revolution!
Anyway, back on topic. I think the best to advice (as apposed to technically best) is to use property files.
- Easy to code
- Easy to debug (this is by far the most important reason, and should not have been point #2)
- It doesn’t instantly break down once your classfiles change (Serialization is rather bad in more than one way)
alright im gonna try out a coupleof these
Well i tried a couple of these and looked them up and horribly failed at doing it right. So could someone post a really good sample source code for how to do this?