admin管理员组文章数量:1516870
@Testpublicvoid testFreeMarker() throws Exception {
//1、创建一个模板文件//2、创建一个Configuration对象
Configuration configuration = new Configuration(Configuration.getVersion());
//3、设置模板文件保存的目录
configuration.setDirectoryForTemplateLoading(new File("G:\\YiLiFang\\yilifang\\e3-parent\\e3-search-web\\src\\main\\webapp\\WEB-INF\\ftl"));
//4、模板文件的编码格式,一般就是utf-8
configuration.setDefaultEncoding("utf-8");
//5、加载一个模板文件,创建一个模板对象。
Template template = configuration.getTemplate("hello.ftl");
//6、创建一个数据集。可以是pojo也可以是map。推荐使用map
Map data = new HashMap<>();
data.put("hello1", "hello freemarker!");
//7、创建一个Writer对象,指定输出文件的路径及文件名。
Writer out = new FileWriter(new File("C:/Users/JYL/Desktop"));
//8、生成静态页面template.process(data, out);
//9、关闭流out.close();
}
java的FileWriter方法,执行抛出异常java.io.FileNotFoundException: C:\Users\JYL\Desktop (拒绝访问。)
文件中写入流,而不是目录,解决办法:将地址具体到文件。Writer out = new FileWriter(new File(“C:/Users/JYL/Desktop/hello.txt”));
版权声明:本文标题:遇到FileWriter拒写的烦恼?这里告诉你如何破解Adobe Flash Player难题 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.betaflare.com/web/1771737825a3268914.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论