Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Program on Text Files

 
Pallavi Chakraborty
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 116
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ...)
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is not a simple deleteLine() method. As Maren suggests, you need to write the code on your own to perform this action.
Layne
 
Naren
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My name is Naren
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic