Copy xml 文件

    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 + "\n");
        }
        writer.append(sb.toString());
        writer.flush();
        writer.close();
        reader.close();
    }

 

posted @ 2015-02-03 14:47  花盛开  阅读(324)  评论(0编辑  收藏  举报