package com.mypcs.utils;
import java.io.*;
import java.util.*;
/** *//**
* 生成Html文件的工具类
* alex 2007-5-29 下午09:54:14
*/
public class CreateHtml {
public CreateHtml(){
}
public String readHtml(String fileName){
StringBuffer sb = new StringBuffer();
try{
fileName = fileName.replaceAll("\\\\", "/");
FileInputStream fis = new FileInputStream(fileName);
BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
String line =reader.readLine();
while(line != null){
sb.append(line);
sb.append("\r\n");
line = reader.readLine();
}
reader.close();
fis.close();
}catch(Exception ex){
return "";
}
return sb.toString();
}
public void writeHtml(String nowPath,String fileName,String s){
try{
//分级建目录
String needBulid = fileName.substring(0, fileName.lastIndexOf("\\"));
needBulid = needBulid.substring(nowPath.length());
String array[] = needBulid.split("\\\\");
nowPath = nowPath.replaceAll("\\\\", "/");
String bulidNow = nowPath.substring(0,nowPath.length()-1);
for (int i = 0; i < array.length; i++) {
String temp = array[i];
if(temp!=null&&temp.length()>0){
bulidNow = bulidNow + "/" + temp;
File file = new File(bulidNow);
while(!file.exists()){
file.mkdirs();
}
}
}
fileName = fileName.replaceAll("\\\\", "/");
File outFile = new File(fileName);
while(!outFile.exists()){
outFile.createNewFile();
}
FileWriter writer = new FileWriter(new File(fileName));
BufferedWriter bufferedWriter = new BufferedWriter(writer);
bufferedWriter.write(s);
bufferedWriter.close();
writer.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
public String setValue(String s,List list,HashMap hashMap){
for(int i = 0; i < list.size(); i++){
String name = (String)list.get(i);
if(name==null){
name = "";
}
String value = (String)hashMap.get(name);
if(value==null){
value = "";
}
value = value.replaceAll("\\$", "#美元#");
s = s.replaceAll("#"+name+"#",value);
}
return s;
}
}
没有乱码问题,呵呵,希望能帮到一些朋友。
posted on 2007-07-16 15:34
Vincent.Yu 阅读(757)
评论(2) 编辑 收藏