package com.whyc.util;
|
|
import java.io.BufferedReader;
|
import java.io.InputStreamReader;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class AnalysisUtil {
|
/*String voltagePredictExePath = "D:\\10小时率电压预估\\voltage_predict_process\\main.exe";
|
String excelSourcePath = "D:\\10小时率电压预估\\测试数据.xlsx";
|
String excelOutPutPath = "D:\\10小时率电压预估\\输出目录";*/
|
public static String voltagePredictExePath="E:\\GitWorkSpace\\fg_v2.0\\target\\10小时率电压预估\\voltage_predict_process\\main.exe";
|
public static String excelOutPutPath="E:\\GitWorkSpace\\fg_v2.0\\target\\outPath";
|
public static String excelSourcePath="E:\\GitWorkSpace\\fg_v2.0\\target\\测试数据.xlsx";
|
|
public static int precent=0;
|
|
public static void analysisXlx(String excelSourcePath, String voltagePredictExePath, String excelOutPutPath){
|
Process mProcess;
|
BufferedReader successResult = null;
|
BufferedReader errorResult = null;
|
try {
|
// 启动进程,进行数据预估
|
List<String> command = new ArrayList<>();
|
command.add(voltagePredictExePath); // 电压趋势预测执行文件路径
|
command.add(String.format("--read=\"%s\"", excelSourcePath)); // 源文件路径
|
command.add(String.format("--write=\"%s\"", excelOutPutPath)); // 输出文件夹
|
ProcessBuilder processBuilder = new ProcessBuilder(command);
|
mProcess = processBuilder.start();
|
if (mProcess == null) {
|
System.out.println("预测主进程启动失败");
|
return;
|
}
|
|
successResult = new BufferedReader(new InputStreamReader(mProcess.getInputStream(), "GBK"));
|
errorResult = new BufferedReader(new InputStreamReader(mProcess.getErrorStream(), "GBK"));
|
String s;
|
while ((s = successResult.readLine()) != null) {
|
if ((s.length() > 0) && !"\n".equals(s)) {
|
System.out.println(String.format("SuccessMsg:%s", s));
|
precent++;
|
}
|
}
|
while ((s = errorResult.readLine()) != null) {
|
if ((s.length() > 0) && !"\n".equals(s)) {
|
System.out.println(String.format("ErrorMsg:%s", s));
|
}
|
}
|
|
if (mProcess != null) {
|
mProcess.waitFor();
|
}
|
} catch (Exception e) {
|
System.out.println(e.getMessage());
|
} finally {
|
safeClose(errorResult);
|
safeClose(successResult);
|
}
|
}
|
/**
|
* 安全的关闭资源
|
*
|
* @param autoCloseable 资源
|
*/
|
public static void safeClose(AutoCloseable autoCloseable) {
|
if (autoCloseable == null)
|
return;
|
|
try {
|
autoCloseable.close();
|
} catch (Exception e) {
|
System.out.println(e.getMessage());
|
}
|
}
|
|
public static int getPrecent(){
|
return precent;
|
}
|
|
public static void main(String[] args) {
|
analysisXlx(excelSourcePath,voltagePredictExePath,excelOutPutPath);
|
}
|
|
}
|