getContentLength没有在Android上的FTP链接工作 [英] getContentLength doesn't work on android for FTP url

查看:146
本文介绍了getContentLength没有在Android上的FTP链接工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继code打印在Android文件大小长度-1,但它适用于桌面Java罚款。
我使用的是Android 2.2的。

Following code prints length -1 for filesize on android, but it works fine on desktop JAVA. I'm using Android 2.2.

URL url1 = null;
URLConnection uconn = null;
try {
     url1 = new URL("ftp://FTPHOST/file.zip");
     uconn = url1.openConnection();
     uconn.setDoInput(true);  
     int len= uconn.getContentLength();
     int headersize = uconn.getHeaderFields().size();
     System.out.println("******************************* "+len);
     } catch (Exception e) {     
        e.printStackTrace();
     } 
return null;

让我知道如果在Android中的任何解决方法获得文件大小。

Let me know if any workaround in android to get filesize..

推荐答案

Android平台的URL连接code使用不同的基地(Apache的HTTP客户端)的引擎盖下,而不是在Oracle JVM的实现。 Apache的HTTP客户端本身不支持FTP下载桌面JVM的方式做。

The Android platform's url connection code uses a different base (Apache HTTP client) under the hood, rather than the Oracle JVM's implementation. Apache HTTP client doesn't natively support FTP download the way the desktop JVM does.

桌面JVM使用一个被历史名为 sun.net.ftp.FtpClient 为FTP功能类。阳光班均不适用于Android,这样是行不通的。你需要让自己的FTP客户端。

The desktop JVM uses a class that was historically named sun.net.ftp.FtpClient for that FTP functionality. None of the sun classes are available on Android, so that doesn't work. You'll need to get your own FTP client.

这篇关于getContentLength没有在Android上的FTP链接工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆