This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes How can I change the character in mid of the file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How can I change the character in mid of the file" Watch "How can I change the character in mid of the file" New topic
Author

How can I change the character in mid of the file

Huzefa Zohaib
Ranch Hand

Joined: Nov 21, 2001
Posts: 40
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

Joined: Mar 05, 2003
Posts: 32
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.


- Donny Nadolny<br />The pen is mightier than the sword, and considerably easier to write with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I change the character in mid of the file