报错:
Exception in thread "main" org.csource.common.MyException: item "tracker_server" in /D:/%e6%a1%8c%e9%9d%a2/javaDemo/ZG_Four/dongyimai-parent/dongyimai-service/dongyimai-file-service/target/classes/fastdfs_client.conf not found
at org.csource.fastdfs.ClientGlobal.init(ClientGlobal.java:96)
at com.util.FastDFSClient.<init>(FastDFSClient.java:24)
at com.file.FastDfsTest.main(FastDfsTest.java:45)
源代码:
/ 使用工具类实现文件上传
String imgPath2="D:\\桌面\\图书\\A-746.jpg";
FastDFSClient fastDFSClient = new FastDFSClient("classpath:fastdfs_client.conf");
path = fastDFSClient.uploadFile(imgPath2, "jpg",null);
System.out.println(path);
工具类中出现乱码的部分代码:
if (conf.contains("classpath:")) {
conf = conf.replace("classpath:", this.getClass().getResource("/").getPath());
}
ClientGlobal.init(conf);
因为项目是在D:\桌面\javaDemo的路径下。所以在获取配置文件的绝对地址的时候路径中出现中文导致乱码。
解决方法:
获取配置文件成功之后加入该代码conf = URLDecoder.decode(conf,"utf-8");
即:
if (conf.contains("classpath:")) {
conf = conf.replace("classpath:", this.getClass().getResource("/").getPath());
conf = URLDecoder.decode(conf,"utf-8");
}