project文件内又一个变量
${pro_name.full
}
- private static Configuration cfg = new Configuration();
- public static void generateFile() throws IOException{
- Map <String, String> map = new HashMap<String, String>();
- map.put("pro_name.full", "项目名");
- cfg.setDefaultEncoding("UTF-8");
- cfg.setDirectoryForTemplateLoading(new File("D:\\"));
- Template template = cfg.getTemplate(".project");
- String tofile = "D:\\.project";
- FileOutputStream fos = new FileOutputStream(tofile);
- OutputStreamWriter osw = new OutputStreamWriter(fos,"utf-8");
- try {
- template.process(map, osw);
- } catch (TemplateException e) {
- } finally {
- osw.close();
- }
- }
private static Configuration cfg = new Configuration();
public static void generateFile() throws IOException{
Map <String, String> map = new HashMap<String, String>();
map.put("pro_name.full", "项目名");
cfg.setDefaultEncoding("UTF-8");
cfg.setDirectoryForTemplateLoading(new File("D:\\"));
Template template = cfg.getTemplate(".project");
String tofile = "D:\\.project";
FileOutputStream fos = new FileOutputStream(tofile);
OutputStreamWriter osw = new OutputStreamWriter(fos,"utf-8");
try {
template.process(map, osw);
} catch (TemplateException e) {
} finally {
osw.close();
}
}
运行后会发现原来的变量,变成了项目名。
freemaker是一个非常不错的框架。由于实习公司用的这个现在不是特别清楚了,回顾回顾