drools规则引擎7550Final版本的KieHelperaddContent方法如何指定字符集格式
KieHelper.addContent()方法默认使用UTF-8字符集格式,如果您需要指定其他字符集格式,可以使用KieServices提供的getBytes()方法将规则内容转换为指定的字符集格式,然后再调用addContent()方法添加规则内容,示例代码如下:
KieServices kieServices = KieServices.Factory.get();
KieHelper kieHelper = new KieHelper();
String ruleContent = "rule \"test rule\"\nwhen\nthen\nend";
byte[] ruleBytes = ruleContent.getBytes(Charset.forName("GBK")); // 指定字符集格式为GBK
kieHelper.addContent(new String(ruleBytes, Charset.forName("GBK")), ResourceType.DRL);
原文地址: https://www.cveoy.top/t/topic/hll7 著作权归作者所有。请勿转载和采集!