2014-12-23 3 views
0

"내부 저장소에"unzip "이라는 폴더를 만든 다음 파일을 내부 저장소"unzip folder "에 압축을 해제하려고합니다. 내가 뭘 잘못하고 있는지 확실하지 않아? 당신이 잘못하면 무엇이 좋을 지 설명해주십시오. 감사합니다내부 저장소의 폴더에 압축 해제

편집 : 문제는 폴더가 생성되고 파일이 압축 해제되지 않는 것입니다.

public void send(View view) { 
    try { 
     File mydir = this.getDir("unzip", Context.MODE_PRIVATE);//create folder in internal storage 
     unzip(getFilesDir().getAbsolutePath(), job_no, getFilesDir() + "/unzip/"); 
    } catch (IOException e) { 

    } 
} 

public void unzip(String filepath, String filename, String unzip_path) throws IOException { 
    InputStream is = new FileInputStream(filepath + filename); 
    ZipInputStream zis = new ZipInputStream(new BufferedInputStream(is)); 

    try { 
     ZipEntry ze; 
     while ((ze = zis.getNextEntry()) != null) { 
      ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
      byte[] buffer = new byte[1024]; 
      int count; 

      String filename_temp = ze.getName(); 
      File fmd = new File(filepath + filename_temp); 

      if (!fmd.getParentFile().exists()) { 
       fmd.getParentFile().mkdirs(); 
      } 

      FileOutputStream fout = new FileOutputStream(unzip_path + filename_temp); 

      while ((count = zis.read(buffer)) != -1) { 
       baos.write(buffer, 0, count); 
       byte[] bytes = baos.toByteArray(); 
       fout.write(bytes); 
       baos.reset(); 
      } 

      fout.close(); 
      //} 
     } 
    } finally { 
     zis.close(); 
    } 
} 
+0

글쎄, 어떤 것이 효과가 있는지 설명하고 싶을 수도 있습니다. 내가 한 번 보는 것은 File mydir = this.getDir ("unzip", Context.MODE_PRIVATE); // 내부 저장소에 폴더를 만듭니다. 실제로 디렉토리를 만들지는 않을 것입니다. –

+0

그래, 그게 좋은 생각이야 롤 –

답변

0

이렇게하면 절대 저장 장치가됩니다.

final static String MEDIA_PATH = Environment.getExternalStorageDirectory().getPath() + "/"; 
+0

그건 외부 저장 장치에서 작동하지만 내부 저장 장치에서 원한다. 감사합니다 –

+0

u가 sdard를 가지고 있지 않다면 내부 저장 경로를 얻을 것이고 u가 sdcard를 가지고 있다면 그것은 외부 저장 경로를 취할 것입니다. 더 중요한 것은 두 가지 모두를 받아 들일 것입니다. –

+0

좋아요, 그래서 폴더 생성을 수정했습니다, 폴더는 이제 제대로 생성됩니다 ....하지만 압축 해제 기능은 여전히 ​​작동하지 않습니다 .. –