我有一个带有多行的字符串,如下所示
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book publishyear="1990">
<name>Harry Potter</name>
</book>
</books>
如何将其写入文件?我尝试过使用缓冲写入器,但是它不会在多行中使用字符串。
try{
FileWriter fstream = new FileWriter("D:/temp.txt");
BufferedWriter out = new BufferedWriter(fstream);
out.write(" <?xml version="1.0" encoding="UTF-8"?>
<books>
<book publishyear="1990">
<name>Harry Potter</name>
</book>
</books>");
out.close();
}catch (Exception e){//Catch exception if any
System.err.println("Error: " + e.getMessage());
}