public static void copyFailFile(String bugID) throws Exception { File file = new File("."); //get XML file path String xmlFilePath = file.getCanonicalPath() + "\Accounting Client\results\Accounting Client.xml"; //new XML file String bugFilePath = file.getCanonicalPath() + "\Accounting Client\results\" + bugID + ".xml"; //read XML file BufferedReader reader = new BufferedReader(new FileReader(new File(xmlFilePath))); //write XML file BufferedWriter writer = new BufferedWriter(new FileWriter(new File(bugFilePath))); String line = ""; StringBuilder sb = new StringBuilder(); while((line = reader.readLine()) != null) { if(line.contains(""")) { line = line.replace(""", """); }else if(line.contains(">")) { line = line.replace(">", ">"); } sb.append(line + " "); } writer.append(sb.toString()); writer.flush(); writer.close(); reader.close(); }