• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

URLybird

 
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can anyone help me please -- I've literally been looking at this problem/bug for the last 2 days solid and am getting nowhere.

Basically -- my question is -- Is there an EOF flag on the .db file?
Currently I just have it in a try/catch(EOF Exception).

Is this sufficient?
I am running into problems.

Basically I dump my whole flat file into a vector -- any time the vector is changed/updated I then write back to a new .txt file.

When I then dump this new .txt file into a new Vector,using the try/catch above,It seems to add in a new blank record.

i.e.e In a nutshell,it seems to recognise the EOF when reading from the original .db file but when it reads from my .txt file,it doesn't recognise the EOF until a full blank record extra?

To sum up -- writing back is not a problem -- it's the reading of the new file.(Not thge reading of teh original file).

Any ideas?
I'm tearing my hair out.
 
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Donal,

There is no EOF indicator in the file format. So your read method is implemented correctly (just keep reading records until the stream indicates EOF is detected).

Based on your description of the problem, I would guess that something goes wrong in writing the file back to disk. Perhaps you write a byte more than you've read? Do your original file and the written file have the same file size?

Frans.
 
donal horgan
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Frans,

I don't know the size of the original .db file I received from sun.
And I didn't specify any size for my .txt file.

I do know for definite 100% that when I write the file back after adding a record,it is definitekly writing it back correctly.
I know this because I have absolutely peppered it with debug.

The problem is when I read my new .txt file which includes the new record.
When I populate my Vector after reading this .txt file it seems to do one extra iteration and fills an extra element in the Vector with blanks.
Which would be fine except when I then add a new record again,these blanks get written as dots(....) to my file.

Baically I have a while(true) until it reached EOF exception handling.
In a nutshell it just doesn't seem to recognise my new .txt End of file until 1 recors length after the end => populates any vector with a new element filled with spacess - which as I say translate to dots when written back again.
 
Frans Janssen
Ranch Hand
Posts: 357
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Donal,

For reading I do something like this, which worked perfectly fine for me:

Frans.
 
donal horgan
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks frans.

I'll give it a go.
 
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you should consider using RandomAccessFile("location of file") and read like this..

{Done with reading start of file contains field description}
RandomAccessFile.readInt(); //for magic cookies
RandomAccessFile.readInt(); //for number of fields
etc..


{Now read schema}
fieldnamelength = RandomAccessFile.readShort(); //field name
byte[] name = new byte[fieldnameLength];
raf.readFully(name);
<now add name to vector>


Now you can add this field name into vactor or anything


like wise do it for actual data as well and add it to different vector. Now you have two vector one with field name and other with actual data. When you pass that to JTable you will see entire data in JTable.
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using DataInputStream and DataOutputStream to read from and write into the file and I read from the file until the readByte() returns -1. Is there special reason for using Random Access file (almost everyone in this forum do so)
 
Hey, I'm supposed to be the guide! Wait up! No fair! You have the tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic