package com.tenwa.httpclient.pboc; import org.apache.commons.codec.binary.Base64; import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; public class FileUtils { /** * xml信息读取并生成xml文件 * @param filePath * @param reportId * @param resXMLReportStr * @return */ public static String createXMLFile(String filePath, String reportId, String resXMLReportStr) throws Exception { // TODO: 2023/1/31 文件地址修改 // String xmlFilePath = filePath + "\\xmlHtml\\"+ reportId +".xml"; String xmlFilePath = filePath + "/xmlHtml/"+ reportId +".xml"; // TODO: 2023/1/31 写入xml文件 File xmlFile = new File(xmlFilePath); xmlFile.createNewFile(); PrintStream printStream = new PrintStream(new FileOutputStream(xmlFile)); printStream.println(resXMLReportStr);//将字符串写入文件 return xmlFilePath; } /** * xml信息读取并生成html文件 * @param filePath * @param reportId * @param htmlRptDataStr * @return */ public static String createHtmlFile(String filePath, String reportId, String htmlRptDataStr) throws Exception { byte[] byteData = new Base64().decode(htmlRptDataStr); // TODO: 2023/1/31 文件地址修改 // String htmlFilePath = filePath + "\\xmlHtml\\"+ reportId +".html"; String htmlFilePath = filePath + "/xmlHtml/"+ reportId +".html"; // TODO: 2023/1/31 html内容写入html文件 File htmlFile = new File(htmlFilePath); htmlFile.createNewFile(); PrintStream printStreamHtml = new PrintStream(new FileOutputStream(htmlFile)); printStreamHtml.println(new String(byteData));//将字符串写入文件 return htmlFilePath; } }