Try this...
//~ Formatted by jFormat�2003 EMail:
[email protected] 2003.07.23
import java.io.*;
import java.util.*;
public class ReadReplaceText {
public static void main(String args[]) throws IOException {
ArrayList inFile = new ArrayList();
ArrayList outFile = new ArrayList();
int iJ=0;
String oldStr = "Nissan Maxima, 5JKLU, Green =2001";//Old_String
String newStr = "Nissan Altima, 6LRTU, Yellow=1999";//New string
try {
FileReader fr = new FileReader("test.txt");// Create a char stream reader
BufferedReader br = new BufferedReader(fr);//A line reader
String str;
while((str = br.readLine()) != null) {
inFile.add(str);//~inFile is an AryFile TYPE
//System.out.println(str);
}
fr.close();
//And now manipulate the file...
for(int iK=0; iK<inFile.size(); iK++) {
str = (String) inFile.get(iK);
System.out.println(str);
iJ = str.indexOf(oldStr);
//iJ will equal 0 when current string matches Old_String
if(iJ == 0) {
outFile.add(iK, newStr);
//System.out.println(">>> " + str);
}
else {
outFile.add(iK, str);
}
}//~for(int iK=0; iK<inFile....
System.out.println();
//Write the File
PrintWriter pw = new PrintWriter(new FileWriter("test.txt"));
for(int iK=0; iK<inFile.size(); iK++) {
str = (String)outFile.get(iK);
pw.println(str);
System.out.println(str);
}
pw.close();
}//~try...
catch (IOException ex) {
ex.printStackTrace();
}
}//~public static void main(...
}//~public class ReadReplace...