wood burning stoves 2.0*
The moose likes Java in General and the fly likes Program on Text Files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Program on Text Files" Watch "Program on Text Files" New topic
Author

Program on Text Files

Pallavi Chakraborty
Ranch Hand

Joined: Jan 18, 2003
Posts: 93
Hello everybody,
I have an application here which takes the choice from a user and does the necessary processing. I am using text files for this.
The following are the three programs:
1. Employee1.java
2. Employee1App.java
3. Employee2.java
I had a couple of doubts:
1.
Employee1App has the main method. Choice3 takes us to Employee2 file which checks if an employee exists. the program is working but it is also printing the catch part of the try-catch statement even after it has successfully executed the try part.
2.
Is there a way to delete a record ..... just like we have readLine() is there a way tp delete a line.

Thank you very much.
Pallavi




Gayathri Prasad
Ranch Hand

Joined: Jun 25, 2003
Posts: 116
Hi,
The possible reason could be because of the readLine() method because after all the records from the text file are read finally the end of file is reached and then the readLine() throws the IOException because there is no more input to read thats the reason I think after u get the out put successfully the catch() part is getting executed.
Please check and let me know..
All the best,
Gaya3
-------------------------------------------------
"Life is a process of Continuous learning"
Pallavi Chakraborty
Ranch Hand

Joined: Jan 18, 2003
Posts: 93
Hello Gaya,
i tried changing the loop from a do-while to a while. I am still getting the error.
May be I am doing something wrong.
Thanks
Pallavi
Pallavi Chakraborty
Ranch Hand

Joined: Jan 18, 2003
Posts: 93
Hello Gayathri,
It worked when I chenged the code to
while(br.ready()
{
//code
}
Can you guide me towards how we can delete a record.
Thanks
Pallavi
Naren
Greenhorn

Joined: Jul 21, 2003
Posts: 23
Hint: delete the line (containing the matching record) from the file and write the remaining contents to the same file. So you need something to hold the contents of the file. You have various options (String, Array of Strings ...)


<a href="http://www.mqtips.com" target="_blank" rel="nofollow">MQMessenger</a> - free Java app for MQSeries
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
There is not a simple deleteLine() method. As Maren suggests, you need to write the code on your own to perform this action.
Layne


Java API Documentation
The Java Tutorial
Naren
Greenhorn

Joined: Jul 21, 2003
Posts: 23
My name is Naren
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Program on Text Files
 
Similar Threads
Problems w/ a HashMap
Compile error
Question on String Tokenizer .
deleting a line from a text file
Help with Println and Scanner