所以我正在做的是,我正在从XML中找到并删除一些标签。删除后,这些标签将被空格替换,这实际上不会影响XML,但是当我删除大量标签时会导致问题。
实现这一目标的任何工作方式?
先谢谢。
Here is the link of the answer I found here but it's not working
答案 0 :(得分:0)
这应该有效:
public static void main(String[] args) {
Scanner file;
PrintWriter writer;
try {
file = new Scanner(new File("src/myXml.xml"));
writer = new PrintWriter("src/myXml2.xml");
while (file.hasNext()) {
String line = file.nextLine();
if (!line.isEmpty()) {
writer.write(line);
writer.write("\n");
}
}
file.close();
writer.close();
} catch (FileNotFoundException ex) {
Logger.getLogger(Test.class.getName()).log(Level.SEVERE, null, ex);
}
}