如何从服务器加载文件并在列表视图中排列?

时间:2013-08-17 15:53:52

标签: android-listview

请帮帮我。我正在创建一个连接到服务器的应用程序,该服务器加载了许多不同的pdf文件并在列表视图中显示它们。单击文件名时,将下载该文件。

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    boolean m=ftpConnect("ftp.andi.site11.com", "a7078185", "hacked@22", 21);
}
public boolean ftpConnect(String host, String username,
         String password, int port)
{

    String TAG="NISHAD";
    try {
        FTPClient mFTPClient = new FTPClient();
        // connecting to the host
        mFTPClient.connect("ftp.andi.site11.com",21);

        // now check the reply code, if positive mean connection success
        if (FTPReply.isPositiveCompletion(mFTPClient.getReplyCode())) {
            // login using username & password
            boolean status = mFTPClient.login("a7078185","hacked@22");
            Toast.makeText(this,"Done!!",Toast.LENGTH_LONG).show();
            /* Set File Transfer Mode
             *
             * To avoid corruption issue you must specified a correct
             * transfer mode, such as ASCII_FILE_TYPE, BINARY_FILE_TYPE,
             * EBCDIC_FILE_TYPE .etc. Here, I use BINARY_FILE_TYPE
             * for transferring text, image, and compressed files.
             */
            mFTPClient.setFileType(FTP.BINARY_FILE_TYPE);
            mFTPClient.enterLocalPassiveMode();

            return status;
        }
    } catch(Exception e) {
        Log.d(TAG, "Error: could not connect to host " +"ftp://andi.site11.com" );
    }

    return false;

}

}

0 个答案:

没有答案