• Post Reply Bookmark Topic Watch Topic
  • New Topic

Modifying Text File By line  RSS feed

 
leonardo ginting
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys
how could i modify text file java by line i.e

i have 4 line and each line i have a words

and i would like to modify line number 2 which is 'bbb'
being rrrr

and how could i do that?

here is my code





if i do this code i got an error because i've closed bw

the error is



thanks guys
any help would be appreciate

BF
Leonardo
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't read and write a file at the same time. You'll need to write to a different file than the one you're reading. After you're done, you can delete the former and rename the latter.
 
leonardo ginting
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulf Dittmer wrote:You can't read and write a file at the same time. You'll need to write to a different file than the one you're reading. After you're done, you can delete the former and rename the latter.


ahhh ok thanks ulf you have given me enlightment thank you so much ulf,,
it means i have to create a new class to for modify the text that ive created right?


BF
Leonardo
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need another class. And there isn't really a "modifying". Just read from one file and write to another.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!