2023-08-16 11:41:21 +08:00

65 lines
2.3 KiB
Java

package com.tenwa.httpclient.pboc;
import com.tenwa.reckon.util.DateUtils;
import org.apache.commons.codec.binary.Base64;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;
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";
SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMM");
filePath = filePath + "/report/"+timeFormat.format(new Date())+ "/";
File targetFolder = new File(filePath);
if (!targetFolder.exists()) {
targetFolder.mkdirs();
}
String xmlFilePath = filePath + 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";
SimpleDateFormat timeFormat = new SimpleDateFormat("yyyyMM");
filePath = filePath + "/report/"+timeFormat.format(new Date())+ "/";
File targetFolder = new File(filePath);
if (!targetFolder.exists()) {
targetFolder.mkdirs();
}
String htmlFilePath = filePath + 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;
}
}