• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How can I change the character in mid of the file

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is a text contaning the following data named "abc.txt".
a b c d e f g h i
j k l m n o p q r
s t u v w x y z
Now I want to change the "n" to "N" in the text file abc.text
I find the position of "n" using the following code.
try {
FileReader readIt = new FileReader("C://abc.txt");
BufferedReader collectData = null;
collectData = new BufferedReader (readIt);
String line= null;
while ((line= collectData.readLine ()) != null) {
if (line.indexOf ('n') > 0) {
/*
Over Here I want to write the code which can change
the letter "n" to letter "N"
*/
} // if
} // while
}catch (Exception ee) {System.out.println (ee);}
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey. The only thing I can think of right now is to read in the file, chance whatever you want to change, then write your new text (with your change) to the same file. As far as I can tell, that's the only way to do it (correct me if i'm wrong).
Hope this helps.
 
"Don't believe every tiny ad you see on the internet. But this one is rock solid." - George Washington
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic