解决saiku读取配置文件乱码

最近使用到 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的编码,这样在前段展示的时候中文乱码就没有了

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值