当前位置:编程学习 > JAVA >>

关于IO读写问题,在线等

String mateKey = "<meta name=\"DC.Type\" content=\"" + key + "\">\r\n";
url = treeNode.getUrl();//从树状结构中获取点击的地址
String strUrl = "E:\\CFG_help\\" + url;
String target = "<meta name=\"DC.Type\"";  //判断是否包含的值
System.out.println(strUrl);
String line;


FileReader fileread;
BufferedReader bufread;
String readStr = "";
fileread = new FileReader(strUrl);
bufread = new BufferedReader(fileread);
RandomAccessFile mm = null;

try {
while ((line = bufread.readLine()) != null) {
if (readStr.indexOf(target) != -1
&& line.indexOf("<title>") != -1) {
readStr = readStr + line + "\r\n";
} else {
readStr.replaceAll(mateKey, target);
readStr = readStr + line + "\r\n";
}
}
String filein = mateKey + "\r\n" + readStr + "\r\n";

mm = new RandomAccessFile(strUrl, "rw");
mm.writeBytes(filein);

} catch (RuntimeException e1) {
e1.printStackTrace();
}

}
这是 我的代码 ,主要逻辑是, 读取一个HTML文件,当HTML文件中没有 target这个属性 ,如果有 就用 mateKey 来替换。如果没有,直接写入,要求是要在<title>属性前面添加 --------------------编程问答-------------------- <html>

<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>如何关闭或启动关联计算算法</title>
<link rel="stylesheet" type="text/css" href="../../CSS/hwhelp.css">
</head>

<body>

<h4>如何关闭或启动关联计算算法</h4><hr>
<h6>问题现象</h6>
<p>用户在“Bill of Configuration”页签中修改部件的数量值,同时需要手动修改该部件相关联部件的数量值,影响用户配置产品的效率。</p>
<h6>解决方法</h6>
<ol>
  <li>在“Project Navigator”导航树中,双击产品节点,在右侧选择“Bill of Configuration”页签。</li>
</ol>
<ol>
  <li value="2">在“Bill of Configuration”页签中,单击<img border="0" src="images/Real-time%20Calculate.png" width="16" height="20">关闭或启动关联计算算法。</li>
  <p><font color="#0000CE"><b>说明:</b></font></p>
<div style="background-color: #FFFFDF">
<font color="#0000CE">当“Enable the association calculation”按钮状态如<img border="0" src="images/Real-time%20Calculate1.png" width="30" height="30">时,表示启动关联计算算法;
当“</font><font color="#0000ce">Disable the association calculation</font><font color="#0000CE">”按钮状态如<img border="0" src="images/Real-time%20Calculate2.png" width="30" height="27">时,表示关闭关联计算算法。</font></div>
</ol>


</body>

</html>


这是HTML文件 --------------------编程问答-------------------- 不知道LZ在说些什么,但是感觉碉堡了的样子 --------------------编程问答-------------------- 代码懒得看了,

不过应该很简单的!

--------------------编程问答-------------------- 你代码是什么错误呀? --------------------编程问答-------------------- 什么错。。是不是strUrl这问题
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,