This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

What approach should be followed?

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a problem which has to deal with a file. The file has header information (about length of record etc) and then actual records. The header information is written using dataoutputstream. But the actual records after that are in the character (ASCI) format.
Now I have to do various operations on this file like:
1. Add record (at the end)
2. Delete record (from anywhere )
3. Search a particular record
5. Modify any field of any given record.
4. Lock a particular record.
I tried with RandomAccessFiles. Searching and adding the record is working fine. But I am not sure if I can lock a particular record if I use this randomaccessfile.
Also I am doing manipulations at byte level. (reading one record at a time, and each field in a separate array and then working on each array depending upon the requirement)
Is there any other/better way to do this? I guess I am not fully utilizing the java’s foundation classes.
Will this cause a problem if I have to make this service available at the server and use the RMI architecture to allow clients to do those operations?
I am quite confused as there are so many ways of dealing with file in JAVA. IS NIO is the best way to do this?
Detail answer is much appreciated.
Thanks in advance.
Manoj
 
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jmannu gundawar:
Hi,
I have a problem which has to deal with a file. The file has header information (about length of record etc) and then actual records. The header information is written using dataoutputstream. But the actual records after that are in the character (ASCI) format.
Now I have to do various operations on this file like:
1. Add record (at the end)
2. Delete record (from anywhere )
3. Search a particular record
5. Modify any field of any given record.
4. Lock a particular record.
I tried with RandomAccessFiles. Searching and adding the record is working fine. But I am not sure if I can lock a particular record if I use this randomaccessfile.
Also I am doing manipulations at byte level. (reading one record at a time, and each field in a separate array and then working on each array depending upon the requirement)
Is there any other/better way to do this? I guess I am not fully utilizing the java’s foundation classes.
Will this cause a problem if I have to make this service available at the server and use the RMI architecture to allow clients to do those operations?
I am quite confused as there are so many ways of dealing with file in JAVA. IS NIO is the best way to do this?
Detail answer is much appreciated.
Thanks in advance.
Manoj



Hi Manoj, I assume you're working on the SCJD assignment, certainly looks like it, if so then maybe you'll get more feedback in the SCJD forum.
anyway, for starters, dont try locking records with RandomAccessFile or any other File object for that matter, NIO provides some locking facilities but dont consider those either, except maybe the entire file as an optional precaution, but since its OS dependent it cant be guarenteed , hence the optional precaution.
anyhat, for locking consider that all your records start at a specific position in the file, so maintain a collection of those positions or record numbers assigned to those positions and treat the positions themselves as locks, so if recNumber 5 is locked and is in position 2314 then dont allow any modifications to that record.
make sense?
 
Manoj Gundawar
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ta ra ki sung.
You are right. This is for SCJD exam. I will probably post this query in that forum.
thanks
manoj
 
Space pants. Tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic