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; }