ftp下载数据乱码
ftp下载数据出现乱码 一个txt文件
URL u3=new URL("ftp://user:password@111.111.111.11:11//vehicle.txt");
urlconn3=u3.openConnection();
in3 = urlconn3.getInputStream();
BufferedReader br3=new BufferedReader(new InputStreamReader(in3));
StringBuffer t3 = new StringBuffer();
while((line=br3.readLine())!=null){
rec=line.split("\t");
String tel=rec[0];
String hpzl=rec[1];
String hphm=rec[2];
String jf=rec[3];
String fsxx1=rec[4];
System.out.println(fsxx1);
String fsxx = new String(fsxx1.getBytes("GBK"), "ISO-8859-1");
// String address=rec[3];
System.out.println(tel+hpzl+hphm+jf+fsxx1);
}
------解决方案--------------------用apache ftpclient吧,部分样例代码
/**
* 获取FTP服务器的客户端 连接对象 FTPClient Author:liuzhaoyang Date:2013-06-24
*
* @param ftpURL
* ftpURL
* @param userName
* ftp server 用户名用户名
* @param passWord
* ftp server 登录密码
* @return ftpClient对象
*/
private static FTPClient ftpClientConnection(String ftpURL, String userName, String passWord, String charSet)
throws
IOException {
if (Objects.equal(userName, null)) {
userName = "anonymous";
}
if (Objects.equal(passWord, null)) {
passWord = "anonymous";
}
List<String> listCharSet = ImmutableList.of("utf8", "utf-8", "gbk", "gb2312");
if (!listCharSet.contains(StringUtils.lowerCase(charSet))) { // 如果charSet不是utf8,gbk,gb2312;就抛出异常
throw new
RuntimeException("该FTP方法目前支持的文件编码有:utf8,gbk,gb2312");
}
String loginInfo = Objects.toStringHelper("").add("ftpURL", ftpURL).add("userName", userName)
.add("passWord", passWord).toString();
logger.info(loginInfo);
FTPClient ftpClient = null;
// try {