• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Restart in a RandomAccessFile

Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've been looking at the posts in the I/O forum and think I've got the basics of an answer, but wanted to walk this thru with someone.

I have to take an existing program that has a property file and input file & process the input file run thru some complex logic. As I process the records in the file (fields that are strings or date delimited by |), I create a backout file which is of the same format - but contains the object I'm modifying BEFORE the update takes place.

I have to be able to do 2 things regarding backout/restore - and not deviate from the format(s) above:
a) Scenario A: User wants us to restart from a restart point in the file (there are certain records that would make sense to restart from)
b) Scenario B: Catastrophe. Don't restart the program. Just backout everything you did from the Backout File.

For Scenario A, I was going to make the input file be RandomAccessFile - looks like using the getFilePointer() will return a long which I can record somewhere (there will be a lag in time for deciding whether to restore or backout) so I can restart later....I wanted to write this pointer to the Properties File (which I also have) so that I could read it as a property - I already also use a Property File (plain File and FileInputStream).
I was looking at this post as a way to do this, but not sure this will work: https://coderanch.com/t/274836/Streams/java/help-writing-file

QUESTION : Will this (the post) work for what I have planned? Can I just define a FileOutputStream for the property file and append a 'long' variable to it? Or is there a better way?

Thanks in advance - and sorry if this is posted somewhere and i did not see it. I tried to do a diligent job of researching b4 the post.
No one can make you feel inferior without your consent - Eleanor Roosevelt. tiny ad:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic