从互联网上下载android文件的android导致解析错误

时间:2010-12-01 20:54:47

标签: android

当我尝试使用以下代码下载文件并运行apk文件时,它总是会导致“解析错误”。我很无能为力。任何帮助表示赞赏。

try
                  {
                   URL url  = new URL("http://10.0.0.1/test.apk"); 
                         URLConnection conexion = url.openConnection(); 
                         conexion.connect();
                         int lenghtOfFile = conexion.getContentLength();
                         InputStream is=url.openStream();
                         FileOutputStream fos=new FileOutputStream("/flash/test.apk");
                        byte data[]=new byte[1024];
                        int count=0;
                        long total=0;
                        int progress=0;

                        while ((count=is.read(data)) != -1) 
                         { 
                             total += count; 
                             int progress_temp = (int)total*100/lenghtOfFile; 
                             if(progress_temp%10 == 0 && progress != progress_temp){ 
                                 progress = progress_temp; 
                                 Log.v("APK Download", "total = "+progress);  
                                // Log.v
                             } 
                             fos.write(data, 0, count); 
                         } 

                         is.close(); 
                         fos.close(); 

                         Log.v("APK Download", "Download Done");  



                  }catch (Exception e){}

1 个答案:

答案 0 :(得分:2)

上帝保佑!我很困惑,然后我仔细查看了上传到腐败的网络服务器上的文件。如果我通过FileZilla上传它会被破坏,如果我使用cpanel上传文件,它的效果很好。谢谢上帝,我花了好几个小时解决这个问题后,能够继续我的编码工作。 :)