File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Random Access Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Random Access Files" Watch "Random Access Files" New topic
Author

Random Access Files

jambeard lewistrix
Greenhorn

Joined: Aug 16, 2005
Posts: 14
I've just started using random access files and need to know what i'm doing wrong.

I've made a test program (just to learn how to work with them) but it dosn't work properlly.

The first part of the program reads in names entered by the user and should work like this:

read in name from user
write to file
repeat until user exits
then add '.' to the end of the file

Then the second reads in the values like this:

read in name
display name
repeat this until '.' char found

The first part of the program definately works. The names get entered and stored in the file and the '.' char gets added to the end of the file.

The second part of the program does not work. If I only enter 1 name in the first program then the second program works, but if I enter more than 1 name then it loops forever outputting null as the name.

This is my code for reading in the names:

Ignore the empty catch statements as this was just a quick test. Also, there's an int called nameNumber in there which is just a number assigned to the name when it is entered in program 1.

Can anyone see what i've done worng?

Cheers,

J
Norm Radder
Ranch Hand

Joined: Aug 10, 2005
Posts: 685
In case no one sees your problem, I'd suggest you try debugging it yourself.
Add some println() statements to the code to show where it is and what the values are. This can be an iterative process while you narrow it down.
How to debug a program is a useful technique to know.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Random Access Files
 
Similar Threads
hashing problem
Random Access Files
I/O question
suncertify.db.Data
How do I declare an arrayList and initilise it in a constructor Method