XMLEvent.writeAsEncodedUnicode
我遇到了一个奇怪的问题。我正在尝试使用 stax 来解析和保存修改后的 xml 文件,但是虽然 Windows 中一切正常,但我在 Linux 中得到一个空文件。我在 springfourms 上只看到一篇关于这个问题的帖子,但没有答案。那么有人遇到同样的问题吗?
示例代码如下:
FileWriter fileWriter = new FileWriter("/home/user/test.xml");
/* SOME CODE */
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
switch (event.getEventType()) {
case XMLEvent.START_ELEMENT: {
event.asStartElement().writeAsEncodedUnicode(fileWriter);
I've bumped on to an strange issue. I'm trying to use stax to parse and save modified xml file but while everything works in Windows - i get an empty file in Linux. I`ve seen only one post on springfourms about this issue but with no answer. So did anybody had the same problem ?
Sample code below:
FileWriter fileWriter = new FileWriter("/home/user/test.xml");
/* SOME CODE */
while (eventReader.hasNext()) {
XMLEvent event = eventReader.nextEvent();
switch (event.getEventType()) {
case XMLEvent.START_ELEMENT: {
event.asStartElement().writeAsEncodedUnicode(fileWriter);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
之后您是否刷新并关闭了
FileWriter
?如果不是,则可能是缓冲问题。(就我个人而言,我会使用包裹在
FileOutputStream
中的OutputStreamWriter
,而不是FileWriter
,因为后者不允许您指定文件编码...)Have you flushed and closed the
FileWriter
afterwards? If not, it could be a buffering issue.(Personally I'd use an
OutputStreamWriter
wrapped around aFileOutputStream
, instead ofFileWriter
, as the latter doesn't let you specify the file encoding...)