Android Can';无法打开下载的文件

Android Can';无法打开下载的文件,android,ftp,download,Android,Ftp,Download,我尝试从ftp下载apk文件,但下载后无法打开该文件。 原始文件和下载的文件大小相同。 我正在使用apachecommons。 我的代码: 首先下载文件 FTPClient client = null; File ExternalDirectory = Environment.getExternalStorageDirectory(); File DownloadFile = new File(ExternalDirectory.getAbsoluteFile()+"//"+"file.apk"

我尝试从ftp下载apk文件,但下载后无法打开该文件。
原始文件和下载的文件大小相同。 我正在使用apachecommons。 我的代码:

首先下载文件

FTPClient client = null;
File ExternalDirectory = Environment.getExternalStorageDirectory();
File DownloadFile = new File(ExternalDirectory.getAbsoluteFile()+"//"+"file.apk");
    try {
        client = new FTPClient();
        client.setControlEncoding("UTF-8");
        client.connect(mServer, 21);
        client.login(mUser,mPassword);
        client.enterLocalPassiveMode();
        client.setFileType(FTPClient.BINARY_FILE_TYPE);
        OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(DownloadFile));
        boolean success = client.retrieveFile("//httpdocs//file.apk", outputStream);
        if (!success) {
            outputStream.close();
            Log.v("Download Status","Not Download");
        } else {
            outputStream.close();
            Log.v("Download Status","Downloaded");
        }
这是开放式apk的第二部分

Uri uri = Uri.fromFile(DownloadFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/apk"); //Maybe it 's different check different website for this
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
我必须说的最后一件事是,你必须在后台做这件事,在3.0 android在前台下载时被阻止后,你应该使用AsyncTask来做这件事。
希望这将对您有所帮助

这两个部分都能很好地工作。非常感谢。问题似乎在于将下载的文件保存到内部存储器中。没问题。祝您有愉快的一天
Uri uri = Uri.fromFile(DownloadFile);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/apk"); //Maybe it 's different check different website for this
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);