String path = test.class.getClassLoader().getResource("users.xml").getPath();
path = URLDecoder.decode(path, "UTF-8");
SAXReader reader = new SAXReader();
Document document = reader.read(new File(path));
………
……
OutputFormat format = OutputFormat.createPrettyPrint();
format.setEncoding("UTF-8");
XMLWriter writer = new XMLWriter(new FileOutputStream(path), format);
writer.write(document);
writer.close();
如上代码执行完之后,对xml文档的改变无法立刻看到效果,但如果new XMLWriter(new FileOutputStream(path), format)中path是磁盘路径时,例如:F://java project//javaWeb//day_02//users.xml,对xml文档的改变,立该就能看到效果;这是为什么啊??? |