RT,我现在有一个html文档,是用一个模板生成的,现在模板有点改东,所以之前生成的静态页面,都需要改动,哪位老师能够指点一下,就是读到某一行,把这一行替换成新的内容,其它内容保持不变!例如:
a.html内容如下: <table style="margin-top:10px " width="94%" border="0" align="center" cellpadding="0" cellspacing="0" class="text"> <TR>
<TD colSpan=2>日语</TD></TR>
<tr>
<TD vAlign=top width=18% >可提供服务:</TD>
<TD width=82% >商务/投资</TD>
</tr>
<tr>
<TD vAlign=top width=18% >要价描述:</TD>
<TD width=82% >面议</TD>
</tr>
<TR>
<TD vAlign=top width=18% > </TD>
<TD width=82% ></TD></TR>
</TABLE>我想把第二行替换成别的如下: <table style="margin-top:10px " width="94%" border="0" align="center" cellpadding="0" cellspacing="0" class="text"> <TR>
<TD colSpan=2>日语</TD></TR>
<tr>
<TD vAlign=top width=18% >土土土土:</TD>
<TD width=82% >土土土土土土</TD>
</tr>
<tr>
<TD vAlign=top width=18% >要价描述:</TD>
<TD width=82% >面议</TD>
</tr>
<TR>
<TD vAlign=top width=18% > </TD>
<TD width=82% ></TD></TR>
</TABLE>谢谢各位老师们了,分不够可以再加!
a.html内容如下: <table style="margin-top:10px " width="94%" border="0" align="center" cellpadding="0" cellspacing="0" class="text"> <TR>
<TD colSpan=2>日语</TD></TR>
<tr>
<TD vAlign=top width=18% >可提供服务:</TD>
<TD width=82% >商务/投资</TD>
</tr>
<tr>
<TD vAlign=top width=18% >要价描述:</TD>
<TD width=82% >面议</TD>
</tr>
<TR>
<TD vAlign=top width=18% > </TD>
<TD width=82% ></TD></TR>
</TABLE>我想把第二行替换成别的如下: <table style="margin-top:10px " width="94%" border="0" align="center" cellpadding="0" cellspacing="0" class="text"> <TR>
<TD colSpan=2>日语</TD></TR>
<tr>
<TD vAlign=top width=18% >土土土土:</TD>
<TD width=82% >土土土土土土</TD>
</tr>
<tr>
<TD vAlign=top width=18% >要价描述:</TD>
<TD width=82% >面议</TD>
</tr>
<TR>
<TD vAlign=top width=18% > </TD>
<TD width=82% ></TD></TR>
</TABLE>谢谢各位老师们了,分不够可以再加!
解决方案 »
- 关于struts标签知道的大神进来看看
- java Serializable接口到底有什么用啊?
- java读取IC读卡器上的数据的原理
- JSTL下载
- 急死了,和预备语句有关的(PreparedStatement),JSP程序编译后不能正常运行.....
- 有关两个IF选择条件的问题
- 求教:请说出jsp,html,javasrcipt的关系。
- 我的http://localhost:8080/页为什么无法显示!!!!在线等待!
- 怎样把jpg或者gif格式的图片保存到sql server 2000中啊?
- 能谈谈对下面一段话的理解吗??(高分求解)
- 简单查找问题?
- 请问WEB2.0是一个社么概念 现在很热 不过我不懂 请那位大侠详细介绍一下
BufferedReader br=new BufferedReader(fr);
StringBuffer strBuf=new StringBuffer();
String line;
int i=1;
while((line=br.readLine())!=null)
{
if(i==2)
strBuf=strBuf.append("(你要修改成的内容)");
else
strBuf=strBuf.append(line);
i++;
}
append()是追加,不是替换啊
package stream;
import java.io.*;
public class StreamTest {
public static void main(String[] args) {
try{
FileReader fr=new FileReader("C:\\stream\\6261.html");
BufferedReader br=new BufferedReader(fr);
StringBuffer strBuf=new StringBuffer();
String line;
int i=1;
while((line=br.readLine())!=null)
{
if(i==90)
strBuf=strBuf.append("(你要修改成的内容)");
else
strBuf=strBuf.append(line);
i++;
}
br.close();
fr.close();
System.out.print(strBuf.toString());
FileWriter fw=new FileWriter("C:\\stream\\6261.html");
BufferedWriter bw=new BufferedWriter(fw);
bw.write(strBuf);
bw.flush();
bw.close();
fw.close();
}catch(FileNotFoundException e){
System.out.print(e.toString());
}catch(IOException ex){
System.out.print(ex.toString());
}
}
}
......
if(i==90)
strBuf=strBuf.append("(你要修改成的内容)\n");
else
strBuf=strBuf.append(line + "\n");
......
软件重用已经成为主流,什么都自己写,开发效率就。你可以尝试用汇编写程序,或者用机器语言写。那能学到很多滴!