Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Storing data in java

rubendelope
 Share

Hello eveyone.

I am trying to store the score of a game I created in java but I dont know how to store it so that when I close the program and the run it again the score from previous times is still there.

Thank you for your time.

 

Link to comment
Share on other sites

Link to post
Share on other sites

for simplicity you could simply go with saving it to a file in a specific format you decide (plain text, XML, Json).

If you want fancier and less prone to be tampered with you can go with creating a scoreboard class with score class children and serialize that.

Link to comment
Share on other sites

Link to post
Share on other sites

Same way you'd do it in pretty much any other programming language. Write the data to the disk. Could be a simple file, could be plain text, could be encoded or even encrypted somehow, doesn't really matter. Check whether a "score file" exists on startup, then load the previous score from it.

 

Here's a starting point:

https://www.baeldung.com/java-write-to-file

https://www.baeldung.com/reading-file-in-java

Remember to quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×