解决saiku读取配置文件乱码

来源:互联网 发布:python 转换为字典 编辑:程序博客网 时间:2024/05/25 21:35

最近使用到 saiku自助查询工具

但是中文乱码问题在saiku中是一个很难处理的问题

下面介绍一下我如何处理读取配置文件乱码问题的

拿saiku给的示例来说

首先要保证 sales.txt文件的编码格式是 utf-8的(这个是不是必须的,暂时不清楚),

其次修改 ClassPathRespurceDataResourceManager类中的load方法

原始方法是这样的:

public void load() {datasources.clear();try {if (repoURL != null) {File[] files = new File(repoURL.getFile()).listFiles();for (File file : files) {if (!file.isHidden()) {Properties props = new Properties();props.load(new FileInputStream(file));String name = props.getProperty("name");String type = props.getProperty("type");if (name != null && type != null) {Type t = SaikuDatasource.Type.valueOf(type.toUpperCase());SaikuDatasource ds = new SaikuDatasource(name, t, props);datasources.put(name, ds);}}}} else {throw new Exception("repo URL is null");}} catch (Exception e) {throw new SaikuServiceException(e.getMessage(), e);}}

修改后的方法是这样的

public void load() {datasources.clear();try {if (repoURL != null) {File[] files = new File(repoURL.getFile()).listFiles();for (File file : files) {if (!file.isHidden()) {Properties props = new Properties();FileInputStream in = new FileInputStream(file);props.load(new InputStreamReader(in, "UTF-8"));String name = props.getProperty("name");String type = props.getProperty("type");if (name != null && type != null) {Type t = SaikuDatasource.Type.valueOf(type.toUpperCase());SaikuDatasource ds = new SaikuDatasource(name, t, props);datasources.put(name, ds);}}}} else {throw new Exception("repo URL is null");}} catch (Exception e) {throw new SaikuServiceException(e.getMessage(), e);}}
从上面两段代码中可以看出,在读取配置文件的时候是在读取的时候设置为 utf-8的编码,这样在前段展示的时候中文乱码就没有了

0 0