2011-08-17 1 views
1

zip 파일을 다운로드하고 sdcard에 저장하는 응용 프로그램이 있습니다. 입력 스트림을 읽는 동안 zipentry=null이 발생하지만 while 블록은 입력되지 않습니다. 누구든지이 문제를 해결하는데 저를 도울 수 있습니까?zip 파일을 다운로드하여 sdcard에 저장하십시오.

  try { 
      // fileInputStream = new InputStream(input); 
      ZipInputStream zipInputStream 
      = new ZipInputStream(new BufferedInputStream(input)); 
      ZipEntry zipEntry=zipInputStream.getNextEntry(); 

      Toast.makeText(getApplicationContext(), "I have entered try block zipentry"+zipEntry,Toast.LENGTH_LONG).show(); 
      System.out.println("Zipentry is"+zipEntry); 

      while ((zipEntry = zipInputStream.getNextEntry()) != null){ 
       Toast.makeText(getApplicationContext(), "Entered into while block",Toast.LENGTH_LONG).show(); 

      String zipEntryName = zipEntry.getName(); 
      File file = new File(to + zipEntryName); 

      if (file.exists()){ 

      } else { 
       if(zipEntry.isDirectory()){ 
       file.mkdirs(); 
       }else{ 
       byte buffer[] = new byte[BUFFER_SIZE]; 
       FileOutputStream fileOutputStream = new FileOutputStream(file); 
       bufferedOutputStream 
       = new BufferedOutputStream(fileOutputStream, BUFFER_SIZE); 
       int count; 

       while ((count 
       = zipInputStream.read(buffer, 0, BUFFER_SIZE)) != -1) { 
       bufferedOutputStream.write(buffer, 0, count); 
       } 

       bufferedOutputStream.flush(); 
       bufferedOutputStream.close(); 
       } 

      } 
      zipInputStream.close(); 
      } catch (FileNotFoundException e) { 
      // TODO Auto-generated catch block 
       Toast.makeText(getApplicationContext(), "File not found",Toast.LENGTH_LONG).show(); 
      e.printStackTrace(); 
      }catch (IOException e) { 
      // TODO Auto-generated catch block 
       Toast.makeText(getApplicationContext(), "Input outout error",Toast.LENGTH_LONG).show(); 
      e.printStackTrace(); 
      } 

답변

0

while 루프에 조건이 있기 전에 이미 하나의 ZipEntry zipEntry=zipInputStream.getNextEntry();이 있습니다. 그대로두고 while 루프에서만 초기화하십시오. 뭔가 같은 :

ZipEntry zipEntry;  
while ((zipEntry = zipInputStream.getNextEntry()) != null){ 
    // 
} 
+0

아니오, 단지 Zipentry의 값을 확인하기 전에 값이 비어 있다는 것을 알게 된 전에 그것을 초기화했습니다. – Ammu