package cn.happy.shangji3;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
public class MyMain {
/**
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Reader reader=new FileReader("f:/Queen.txt");
BufferedReader br=new BufferedReader(reader);
String line;
StringBuffer sBuffer=new StringBuffer();
//循环读取并追加字符
while((line=br.readLine())!=null){
sBuffer.append(line);
}
System.out.println("替换前:"+sBuffer);
Writer writer=new FileWriter("f:/Queen.txt");
BufferedWriter bw=new BufferedWriter(writer);
//替换后内容
String sbString=sBuffer.toString().replace("{name}", "静静");
sbString=sbString.replace("{type}", "狗狗");
sbString=sbString.replace("{master}", "Queen");
System.out.println("替换后:"+sbString);
bw.write(sbString);
bw.close();
writer.close();
br.close();
reader.close();
}
}