标签:des io os ar java for 文件 c on
private static VelocityContext vc;
static {
vc = new VelocityContext();
}
public static void generateFile(String tempatePath, String destPath, Map<String, Object> attributes) {
Template template = Velocity.getTemplate(tempatePath, "UTF-8");
for (String key : attributes.keySet()) {
vc.put(key, attributes.get(key));
}
BufferedWriter bw = null;
try {
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(destPath), "UTF-8"));
template.merge(vc, bw);
bw.flush();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (bw != null) {
try {
bw.close();
} catch (IOException e) {
}
}
}
}
public static void main(String[] args) {
Map<String, Object> attributes = new HashMap<String, Object>();
attributes.put("key", "value");
generateFile("路径/temp.vm", "路径/dest.html", attributes);
}
标签:des io os ar java for 文件 c on
原文地址:http://my.oschina.net/miger/blog/323149