• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem Writing to FileOutputStream

 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I tried writing a new record to db.db file once and the write was succesful. If I continue to write to the same record the writes are successful. But when I try writing to another record, somehow I get a bunch of garbage in my
db.db file. There may be an obvious reason for this, but because I haven't done any File I/O before this project, I don't have a clue why this would be happening. Any suggestions will be appreciated.
(j.l. edited subject)
[ October 14, 2002: Message edited by: Junilu Lacar ]
 
Ron Newman
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your subject says you are writing to an input stream -- did you mean an output stream? This may or may not be relevant to your problem.
 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops!!! That's a typo. I mean FileOutputStream.
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ronnie,
It's hard to judge without seeing the code, but you may not be resetting your filepointer properly.
All best,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
[ October 14, 2002: Message edited by: Max Habibi ]
 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Max,
I'll check my file pointer and see if that's the problem. If I'm setting my file pointer wrong, shouldn't it just write at the wrong position. Why would there be garbage at the header?
 
Max Habibi
town drunk
( and author)
Sheriff
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ronnie Phelps:
Max,
I'll check my file pointer and see if that's the problem. If I'm setting my file pointer wrong, shouldn't it just write at the wrong position. Why would there be garbage at the header?

Well, you might be pointing at the header. You might also be opening in append mode, etc.
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
 
Ronnie Phelps
Ranch Hand
Posts: 329
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know what's up with the FileOutputStream. I had to specify a mode before the size of the output stream changed from zero. But either way it looked as though it was appending whether I set append mode or not.
Anyway, I used a RandomAccessFile and everything works okay.
By the way I'm still not done with this beta exam. I don't plan to pass but at least I know that the exam is in arms reach now and when I pay for the exam my company will reimburse me anyway. So I'm gonna finish up in the next two hours just so I can have the oppurtunity take the follow up exam and use it as a learning experience.

Thanks again max.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic