java追加到文件 [英] java append to file

查看:126
本文介绍了java追加到文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用谷歌搜索了一段时间,但似乎无法找到它,它应该很容易。我想将CR附加到我用Transformer创建的XML文件的末尾。有没有办法做到这一点>

I googled for this for a while but can't seem to find it and it should be easy. I want to append a CR to then end of an XML file that I am creating with a Transformer. Is there a way to do this>

我尝试了以下但是这导致了一个空白文件?

I tried the following but this resulted in a blank file?


Transformer xformer = TransformerFactory.newInstance().newTransformer();
xformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "file:///ReportWiz.dtd");
xformer.transform(source, result);
OutputStream writer = new FileOutputStream(file);
Byte b = '\n';
writer.write(b);
writer.close();


推荐答案

简单......只是添加追加选项:

Simple... just add the append option:

    new FileOutputStream(f, true /* append */);

这篇关于java追加到文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆