This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I change the character in mid of the file

 
Huzefa Zohaib
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • 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);}
 
Donny Nadolny
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic