Android 如何从ftp服务器下载.txt文件

Android 如何从ftp服务器下载.txt文件,android,Android,我必须从我的服务器下载一个.txt格式的文件到我的android机器上。但我不知道如何从服务器下载一个包含用户名和密码的文件。有人帮我吗。我是android编程新手 查找commons net apache库-。它提供了一个使用FTP的工具 代码示例 FileOutputStream videoOut; File targetFile = new File("path"); FTPClient ftpClient = new FTPClient(); try {

我必须从我的服务器下载一个.txt格式的文件到我的android机器上。但我不知道如何从服务器下载一个包含用户名和密码的文件。有人帮我吗。我是android编程新手

查找commons net apache库-。它提供了一个使用FTP的工具

代码示例

    FileOutputStream videoOut;
    File targetFile = new File("path");

    FTPClient ftpClient = new FTPClient();
    try {
        ftpClient.connect("your.ftp.address", 21);
        ftpClient.enterLocalPassiveMode();
        ftpClient.login("login", "password");

        ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);// Used for video
        targetFile.createNewFile();
        videoOut = new FileOutputStream(targetFile);
        boolean result=ftpClient.retrieveFile("/" + "filename-to-download", videoOut);

        ftpClient.disconnect();
        videoOut.close();    

    } catch (IOException e) {
        e.printStackTrace();
    } catch (Exception e){
        e.printStackTrace();
    }

选中此线程可以使用FTPClient.ASCII\u文件类型。要了解差异,请阅读