欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Drools 决策表转drl

程序员文章站 2022-07-15 19:41:42
...
在drools5.0中,org.drools.decisiontable.SpreadsheetCompiler这个类可以把xls文件流转化为drl的String对象,通过FileWriter来写成drl文件,相关的转换代码是:
public String drlString(String file,String toDir) throws Exception{
SpreadsheetCompiler sc = new SpreadsheetCompiler();
File f = new File(file);
String fileName = f.getName();
String name = fileName.substring(0,fileName.lastIndexOf("."));
FileInputStream xlsStream = new FileInputStream(f);
String drlFileTmp = sc.compile(xlsStream, InputType.XLS);
drlFileTmp.replaceAll(".xls", ".drl");
File drlFile = new File(toDir + "/" + name + ".drl");
FileWriter writer = new FileWriter(drlFile);
writer.write(drlFileTmp);
writer.close();
return drlFileTmp;
}