• Post Reply Bookmark Topic Watch Topic
  • New Topic

Creating an XML issue?  RSS feed

 
Jordan Ruetz
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
So, I am a beginning programmer and was learning how to make an XML. It was for a simple game and only needs to hold the highscores of three different levels. Here is what I coded:


My issue is that I run this code every time I create the program and the scores are reset to 0. How can I make a small change so that I only run this block of code and create the XML the first time the program is run?

I appreciate any help.
 
Paweł Baczyński
Bartender
Posts: 2085
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check if highScores.xml exists.

There is exists method in File class.
 
Jordan Ruetz
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought of that but didn't know if it could be done. How could I do this? Thank you.
 
Paweł Baczyński
Bartender
Posts: 2085
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create an instance of File class.
Then check if the file exists.
 
Jordan Ruetz
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, it works!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!