Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

accessing opened file  RSS feed

 
nan sud
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello

I am writing a header record and large number of data records and a trailor record. I would get the count of data records only after I finished writing the data records. The problem is I need to put this count in the hearder itself. How can we do this?
I don't want to re-open the file and write the count in the header record, after closing it as it consists of huge data and also I don't want to pre-process to get the count before i write.

thanks for your help .
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use java.io.RandomAccessFile; when you know the actual number of records, rewind the file back to the header and write it over again with the correct numbers.
 
nan sud
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks. that helped
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!