• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

DataInputStream and DataOutputStream in Jar file (no need to reply now)

 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello. I've been learning I/O recently and everything seems fine except for when i put my program into a jar file.

My current program is a game that tests how fast you can type the alphabet and i want it to store the fastest time, which is a double variable in a file. I wanted to use serialisation instead of just using a text file.

Basically my program, when it loads, it tries to read a file that has the highest score in it, if the file isn't there my program catches an exception and then calls a method to write the file. It then saves the fastest time whenever someone beats the old time. This worked absolutely fine! Just how i hoped it would work unitl i put my program into a jar file. Now my program creates the file once opened like it is supposed to but it won't save anything.

I earlier had another program that saved to txt. Even as a jar file this worked fine as long as the files were in the same folder as the application so i had wrongly assumed it would work the same way.

Underneath i will put the code for the methods that read and write from the file. And underneath that i will put the whole class just in case anyone is interested in seeing it. Please can anyone give me some advice on how to handle this and what i need to look into.






And here is the whole class.


 
Neil Cartmell
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok this is embarrassing. It turns out it's just a bug in my code, It DOES save but just not the first time. I have to beat the high scrore twice for it to save. So it turns out it's just my error. Not sure what the problem yet is but i'm sure i will find it pretty quick.

I hope no one wasted their time reading this. Sorry!

edit: And if any one is interested. I just had to swap lines 81 and 82 over for it to work properly!
 
Note to self: don't get into a fist fight with a cactus. Command this tiny ad to do it:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic