无法读取从FTP文件中的android? [英] unable to read file from ftp in android?

查看:225
本文介绍了无法读取从FTP文件中的android?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从FTP服务器上的文件读取数据。这片code完全在Java时,我从我的桌面计算机上运行。我复制了同样的code到Android和我正在一个例外。唯一的例外是:

java.io.IOException异常:无法连接到服务器:无法检索文件:550

我不知道为什么它是当同一code正在perfecty在java中发生的。 在Java code是:

 的String =FTP://用户名:password@ftp.mysite.x10.mx:21 / sg1996text.txt;类型=我;
    网址U;
    字符串型F =;
    尝试 {
        U =新的URL(S);
        URLConnection的UC = u.openConnection();
        的BufferedInputStream双=新的BufferedInputStream(uc.getInputStream()); //这是例外,我提出的。
        的System.out.println(打开);
        INT I;
        而((ⅰ= bis.read())!=  -  1)
            F = F +(字符)我;
        的System.out.println(文件读取);
    }赶上(MalformedURLException异常E){
        // TODO自动生成的catch块
        e.printStackTrace();
    }赶上(IOException异常E){
        // TODO自动生成的catch块
        e.printStackTrace();
    }
 

解决方案

删除:

 ;类型= I
 

这是您的网址:

 的String =FTP://用户名:password@ftp.mysite.x10.mx:21 / sg1996text.txt;类型=我;
 

它工作在我的应用程序。

I am trying to read data from a file from ftp server. This piece of code works perfectly in java when i run from my desktop computer. I copied over the same code to android and i am getting an exception. The Exception is:

java.io.IOException: Unable to connect to server: Unable to retrieve file: 550

I have no idea why it is occurring when the same code is working perfecty in java. The java code is:

String s = "ftp://username:password@ftp.mysite.x10.mx:21/sg1996text.txt;type=i";
    URL u;
    String f="";
    try {
        u = new URL(s);
        URLConnection uc=u.openConnection();
        BufferedInputStream bis=new  BufferedInputStream(uc.getInputStream()); //This is where exception i raised.
        System.out.println("IS opened");
        int i;
        while((i=bis.read())!=-1)
            f=f+(char)i;
        System.out.println("File Read");
    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } 

解决方案

Remove:

;type=i

from your URL:

 String s = "ftp://username:password@ftp.mysite.x10.mx:21/sg1996text.txt;type=i";

It works in my application.

这篇关于无法读取从FTP文件中的android?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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