- 原来的代码:
public void createHtmlFile(InfoPublishForm infoPublishForm){
String data = infoPublishForm.getContent().replaceAll("src=\"/DNSFile/Img/news/",
"src=\"../Img/news/");
String path=AppContext.current().getConfig().getProperty("runtime.attchment.rootPath")+
AppContext.current().getConfig().getProperty("runtime.cdn.news.rootPath")+infoPublishForm.getNewsid()+".html";
String dirPath=AppContext.current().getConfig().getProperty("runtime.attchment.rootPath")+
AppContext.current().getConfig().getProperty("runtime.cdn.news.rootPath");
BufferedReader br = null;
PrintWriter out = null;
File dir=new File(dirPath);
File html=new File(path);
try {
if (!dir.exists()) {
dir.mkdirs();
}
if(!html.exists()){
html.createNewFile();
}
byte bytes[]=new byte[512];
bytes=data.getBytes();
int b=data.length();
FileOutputStream fos=new FileOutputStream(html);
fos.write(bytes,0,b);
fos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
pushToCdn(path);
}
-
生成的文件:
image.png
原因:将字符串转为字节流的时候没有设置编码,修改
bytes=data.getBytes("UTF-8");
image.png
解决了