aspose file tools*
The moose likes Java in General and the fly likes Errors when reading and writing from a text file - any help!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Errors when reading and writing from a text file - any help!!" Watch "Errors when reading and writing from a text file - any help!!" New topic
Author

Errors when reading and writing from a text file - any help!!

celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm currently writing a test main class for a BorrowerList and Borrower class. Within the main class, I need to be able to read and write to a file, so users can add details about borrowers such as name, telephone number etc.

I am currently able to save one borrower to the file, but I am then unable to read the file back, as it reports an error of,



Strangely enough, if I then manually edit the text file and remove the membership number and borrower limit, which are both integers, from the start of the line in the text file, it will then allow further borrowers to be added.

Then, the problem becomes that the test main class still doesn't save the value for the membership number or the borrower limit, which the user has input using the keyboard. Instead, it just saves '0 0'.

I am really lost as to why this might be happening. Any ideas??

My code so far is as follows,

1. Main class for testing the other classes,



2. BorrowerList class,



Any help or advice would be gratefully appreciated!!
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
It's hard to say what happens during I/O, because the Borrowers.saveTo method is not shown. A first step might be to ascertain that the values actaully are entered correctly, by printing them out before saving.


Ping & DNS - updated with new look and Ping home screen widget
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

The Borrower class saveTo method saves the following,



where the getForename(), getSurname(), etc methods are inherited from a Person class. The Borrower class simply extends the Person class.

Any idea why the main class, as listed in the original thread, would save only the strings and not the integers?

Any help or advice really appreciated!!
celine scarlett
Ranch Hand

Joined: Nov 06, 2005
Posts: 93
Hi,

I'm very glad to say that the problem has now been solved. I was declaring two method variables within the Borrower class constructor, and not allowing the value to actually reach the variable in that constructor, as specified in the previous class constructor.

Thanks to everybody for their help.

Have a great weekend!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Errors when reading and writing from a text file - any help!!
 
Similar Threads
Reading strings from a line problem _ any help!!
manager class with testing - any help please!!!
Error in run method and class - help!
Calling a method from another class?
Creating a new object from a text file - please help!!