2012-06-09 2 views
2

내가 여러 파일이 전화안드로이드를 큰 파일

내가 코드를 수행했지만 코드는 나 같은 그림/사진으로 작은 크기로 다운로드 할 수 있습니다로 웹에서 다운로드해야합니다. .apk와 같이 약 2MB에서 100MB가 넘는 대용량 파일은 실패 할 것입니다. 아래 코드 :

final ProgressDialog progress=ProgressDialog.show(this, "Please wait", "Loading ...", true); 

     new Thread() 
     { 
      public void run() 
      {    
       try { 
        URL url = new URL("http://www.domain.com/apk/Gmail.apk"); 

        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); 

        urlConnection.setRequestMethod("GET"); 
        urlConnection.setDoOutput(true); 

        urlConnection.connect(); 

        File SDCardRoot = Environment.getExternalStorageDirectory(); 
        File file = new File(SDCardRoot, "Gmail.apk"); 

        FileOutputStream fileOutput = new FileOutputStream(file); 

        InputStream inputStream = urlConnection.getInputStream(); 


        byte[] buffer = new byte[1024]; 
        int bufferLength = 0; 

        while ((bufferLength = inputStream.read(buffer)) > 0) { 
          fileOutput.write(buffer, 0, bufferLength); 
          //downloadedSize += bufferLength; 
        } 
        fileOutput.close(); 

      } catch (MalformedURLException e) { 
        e.printStackTrace(); 
      } catch (IOException e) { 
        e.printStackTrace(); 
      } 
       progress.dismiss();      
      } 
     }.start(); 
+0

표시되는 오류 오류는 무엇입니까? 시간 초과 문제 인 경우 HttpUrlConnection을 사용하면 제한 시간 임계 값을 설정할 수 있습니다. – Geoff

답변

2

그에 대한 링크의 코드에 따라 사용하십시오, 당신을 도움이 될 수 있습니다.

Download File

+0

완벽! 감사 :) – melvintcs