마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

jazzlib 라이브러리를 이용해서 zip 파일 압축풀기를 하는데

0 추천

jazzlib 라이브러리를 이용해서 zip 파일 압축풀기를 하는데

압축풀기가 안됩니다

윈도우에서 압축된 zip 파일을 안드로이드에서 압축을 풀려구했는데

아래의코드에서 

while((bytes_read = in.read(buf)) != -1){
                System.out.println("bytes_read : " + bytes_read);
                out.write(buf, 0, bytes_read);
            }

디버깅을 해보면

위부분에서 계속 루프를 돌면서 넘어가지를 않습니다

while 루프를 벗어나지를 못하고 죽는것같습니다

압축된파일에 여러개의 파일이 있는데 첫번째파일(.dll) 은 압축을 풀고

두번째파일 crypto.dll 파일을 풀려구하는데 while  루프를 벗어나지를 못합니다

어디서 잘못되었는지를 알아내려면 어떻게 테스트를 해봐야될까요?

윈도우에서 압축한것을 안드로이드에서는 풀지못하는걸수도있는지요?

경험있으신분 조언부탁드립니다

 

public static void unZipFile(String targetZip, String completeDir, boolean isDirCre) throws Exception {
    ZipInputStream in = null;
    try{
        File fCompleteDir = null;
        fCompleteDir = new File(completeDir);
        if(isDirCre){
            //폴더가없을경우 생성
            fCompleteDir.mkdirs();
        }

        //zip 파일의 input stream 을 읽어들인다
        in = new ZipInputStream(new FileInputStream(targetZip));
        ZipEntry entry = null;
        //input stream 내의 압축된파일들을 하나씩 읽어온다
        while((entry = in.getNextEntry()) != null){
            //zip파일의 구조와 동일하게 가기위해 로컬의 폴더구조를 만든다 (entry.isDirectory()안먹음 )
            String entryName = entry.getName();
            if(entry.getName().lastIndexOf('/') > 0){
                String mkDirNm = entryName.substring(0, entryName.lastIndexOf('/'));
                System.out.println("mkDirNm : " + mkDirNm);
                new File(completeDir + mkDirNm).mkdirs();
            }

            //해제할 각각의 파일의 outputstream  을생성
            FileOutputStream out = new FileOutputStream(completeDir + entry.getName());

            int bytes_read;
            while((bytes_read = in.read(buf)) != -1){
                System.out.println("bytes_read : " + bytes_read);
                out.write(buf, 0, bytes_read);
            }

            //하나의파일이 압축해제되었다
            out.close();
        }

    }catch (Exception e){
        throw  new Exception(e);
    }finally {
        //모든파일의압축이 해제되면 inputstream 을닫는다
        in.close();
    }
}

 

 

잡부 (5,060 포인트) 님이 2020년 4월 1일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...