jQuery in Action, 2nd edition*
The moose likes Beginning Java and the fly likes modifying file data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "modifying file data" Watch "modifying file data" New topic
Author

modifying file data

ramakrishna ranga
Greenhorn

Joined: Sep 22, 2007
Posts: 3
Text file contains following data

artist1
title1
1
artist2
title2
2
artist3
title3
0
artist4
title4
-1

I want to modify it as

artist1
title1
1
artist2
title2
2
artist3
title3
0

by deleting the strings of
artist4
title4
-1

This is my code


My problem is its deleting whole data from file. please any one tell me how can i delete particular data in a file.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by ramakrishna ranga:
...My problem is its deleting whole data from file. please any one tell me how can i delete particular data in a file.

I'm not sure I'm following your logic, but I don't see any decision-making code for what to keep and what to delete. Something like...

[ September 26, 2007: Message edited by: marc weber ]

"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
I see the deletion is in the replaceAll.

The problem is that you call flush on the FileWriter fr and then close it.
You should call the flush on the BufferedWriter br.
 
 
subject: modifying file data
 
Similar Threads
Error in FileReader
Reading a tab delimited txt file and replacing blanks with zeores.
Bad code - Help me fix it
Need help with read method
Compiled but I need a little more help :[