0
.xls, .apk, .png 등 모든 종류의 파일과 폴더를 압축 해제하고 싶습니다. 그러나 모든 파일을 압축 해제하는 동안 새로 추출 된 폴더 또는 폴더 폴더). .xml, .png, .apk 파일은 올바른 형식이 아닙니다. 내가 열 때 xls 파일은 형식이 다를 수 있으며 파일을 열 때 모든 내용이 다른 형식으로 표시됩니다. .png 파일도 열 수 없으며 .apk는 추출 후에도 유용하지 않습니다. 왜 일어나고있는거야 ?? **압축 해제 파일이 정확한 형식이 아닙니다.
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class UnzipFiles {
public static void main(String a[]){
UnzipFiles mfe = new UnzipFiles();
mfe.unzipFile("E:/New folder/pics.zip");
}
public void unzipFile(String filePath){
FileInputStream fis = null;
ZipInputStream zipIs = null;
ZipEntry zEntry = null;
try {
fis = new FileInputStream(filePath);
zipIs = new ZipInputStream(new BufferedInputStream(fis));
while((zEntry = zipIs.getNextEntry()) != null){
try{
byte[] tmp = new byte[25*1024*1024];
FileOutputStream fos = null;
/*String opFilePath = "E:/New folder/new/"+zEntry.getName();*/
String opFilePath= "E:/New folder/new"+File.separator+zEntry.getName();
File f = new File( opFilePath);
if(zEntry.isDirectory())
{ f.mkdirs();
System.out.println(f.getName()+" "+"folder created");
}
else{
System.out.println(f.getName());
/*System.out.println("Extracting file to "+opFilePath);*/
fos = new FileOutputStream(f);
BufferedOutputStream out = new BufferedOutputStream(fos);
int size = 0;
int k= zipIs.read(tmp);
System.out.println(k+1);
while((size = zipIs.read(tmp)) != -1){
out.write(tmp, 0 , size);
}
}
} catch(Exception ex){
ex.printStackTrace();
}
}
zipIs.closeEntry();
zipIs.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException exc) {
// TODO Auto-generated catch block
exc.printStackTrace();
}
}
}
**
"모든 폴더의 압축을 풀려고합니다."라는 말은 압축 된 파일에 많은 수의 폴더가 있고 그 폴더에 다른 종류의 파일이 들어 있음을 의미합니다. 나는 압축을 푼 파일이 다른 포맷/유니 코드를 가지고 있다고 생각합니다. – user2228673
@ fge 당신이 그것을 자세히 설명해 주시겠습니까? 나는 자바에 초보자이며, 당신의 의견을 이해할 수 없다는 것이 폭 넓은 의미로 설명 해주십시오. – user2228673
int k = zipIs.read (tmp); 이 기능이 무엇을 반환하는지 확인하는 데 사용됩니다. 나는이 라인이이 코드에서 어떤 의미를 가지고 있다고 생각하지 않는다. – user2228673