JAVA 替換 文字檔案內容
JAVA 替換 文字檔案內容
資料來源:http://www.blueshop.com.tw/board/FUM20041006152546UBK/BRD20050302135958J5S.html
import java.io.*;
public class testfile{
public static void main( String args[] ) throws Exception
{
BufferedReader in = new BufferedReader(new FileReader(@”C:\testin.txt”));
BufferedWriter out = new BufferedWriter(new FileWriter(@”C:\testout.txt”));
String str;
while ((str = in.readLine()) != null) {
out.write(str.replaceAll(“Test”,”Abcd”));
out.newLine();
}
out.close();
in.close();
}
}