非常了得 刘阳,taohui.org,电取暖器
问题描述:
使用org.apache.commons.net.ftp.ftpclient创建中文目录、上传中文文件名时,目录名及文件名中的中文显示为“??”。
原因:
ftp协议里面,规定文件名编码为iso-8859-1,所以目录名或文件名需要转码。
解决方案:
1.将中文的目录或文件名转为iso-8859-1编码的字符。参考代码:
name=new string(name.getbytes("gbk"),"iso-8859-1");// 转换后的目录名或文件名。
// make directory
if (path != null && !"".equals(path.trim())) {
string[] pathes = path.split("/");
for (string onepath : pathes) {
if (onepath == null || "".equals(onepath.trim())) {
continue;
}
onepath=new string(onepath.getbytes("gbk"),"iso-8859-1");
if (!ftpclient.changeworkingdirectory(onepath)) {
ftpclient.makedirectory(onepath);
ftpclient.changeworkingdirectory(onepath);
}
}
}
result = ftpclient.storefile(new string(filename.getbytes("gbk"),"iso-8859-1"), new fileinputstream(file));
} catch (exception e) {
e.printstacktrace();
} finally {
ftpclient.logout();
}
return result;
}
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
浅析我对 String、StringBuilder、StringBuffer 的理解
使用IDEA搭建SSM框架的详细教程(spring + springMVC +MyBatis)
Springboot整合freemarker 404问题解决方案
引入mybatis-plus报 Invalid bound statement错误问题的解决方法
网友评论