java/io文本替换

来源:百度知道 编辑:UC知道 时间:2024/06/02 04:13:23
我想把一个文本时面的汉字批量替换成相应的代码。

如:文本内容:

<mx:Canvas width="366" height="120">
<mx:FormItem label=" 用户名称:" fontSize="12" color="#ffffff" width="250" x="40">
<mx:FormItem label=" 登陆密码:" fontSize="12" color="#ffffff" width="256" y="33" x="40">

我就是想把用户姓名和登陆密码。一次性换成name password
有没有通用方法啊!
有没有具体实现在代码啊。看不明白!!

public void create(String filePath){
try{
String title= "MakeHtml ";
String content= "what ' s you speak is not easy to understand@@@!";
//String editer= "test";
//filePath = " ";
//filePath ="/c:/moban.jsp";
System.out.print(filePath);
String templateContent= " ";
FileInputStream fileinputstream = new FileInputStream(filePath);
// 读取模板文件
int lenght = fileinputstream.available();
byte bytes[] = new byte[lenght];
fileinputstream.read(bytes);
fileinputstream.close();
templateContent = new String(bytes);
System.out.print(templateContent);
templateContent=templateContent.replaceAll( "0000000",title);
templateContent=templateContent.replaceAll( "1111111",content);