I have a string with multilines in it as shown below
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book publishyear="1990">
<name>Harry Potter</name>
</book>
</books>
how do I write this to a file? I have tried with buffered writer but, it doesn't take the string in multiline.
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());
}