velocity生成文件的中文问题
程序员文章站
2022-05-02 20:27:04
...
用velocity生成文件,使用UTF-8编码中文问题的解决:
Properties p = new Properties();
//设置输入输出编码,可以放到velocity的配置文件中
p.setProperty("input.encoding", "UTF-8");
p.setProperty("output.encoding", "UTF-8");
...
VelocityEngine ve = new VelocityEngine();
ve.init(p);
...
template = ve.getTemplate(templateName, "UTF-8");//以utf-8编码读取
...
FileOutputStream fos = new FileOutputStream(filename);
BufferedWriter writer = null;
writer = new BufferedWriter(new OutputStreamWriter(fos, "UTF-8"));//以utf-8编码保存
其实很简单,只要注意以utf-8编码的方式读取保存就可以了。
上一篇: C++——封装