首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java连接ftp服务器下载文件有关问题

2012-01-29 
java连接ftp服务器下载文件问题java连接ftp服务器下载文件下载下来的文件打开后格式不对,exe文件不能运行,

java连接ftp服务器下载文件问题
java连接ftp服务器下载文件

下载下来的文件打开后格式不对,exe文件不能运行,pdf文件内容为空
只有txt文件可以正确显示。

是不是编码问题?还是程序不对。

主要代码如下:

                myFtp.openServer(hostname);
                myFtp.login(username,password);
                myFtp.binary();

                        TelnetInputStream   is   =   myFtp.get(this.dldir   +   "/ "   +   fileName);
                        BufferedReader   br   =   new   BufferedReader(new   InputStreamReader(is));
                       
                        StringBuffer   sb   =   new   StringBuffer();
                        int   length;
                        char   buffer[]   =   new   char[1];
                        while((length   =   br.read(buffer,0,1))   !=   -1)   {
                        sb.append(buffer);
                        }
                       
                        byte   buf[]   =   sb.toString().getBytes();
                       
                        FileOutputStream   f1   =   new   FileOutputStream(this.bdldir   +   "/ "   +   fileName);
                        f1.write(buf);

[解决办法]
使用过滤流
[解决办法]
byte buf[] = new byte[2048];
把byte数组的值设大点啊

热点排行