구현의 일종을 수행했습니다. 모든 파일을 생성 할 때 zip 파일이 생성되고 디렉토리 구조를 만들지 않고도 모든 파일이 포함됩니다. 파일을 압축 해제하면 디렉토리 구조가없는 모든 파일이 보입니다.. {동일한 디렉토리 구조를 포함하는 파일을 압축 및 압축 해제하는 방법
File dir = new File(path);
String list[] = dir.list();
String name = path.substring(path.lastIndexOf("/"), path.length());
String n = path.substring(path.indexOf("/"), path.lastIndexOf("/"));
Log.d("JWP", "New Path :"+n);
String newPath;
if(!dir.canRead() || !dir.canWrite()){
return;
}
int len = list.length;
if(path.charAt(path.length() - 1) != '/'){
newPath = n + "/";
}
else{
newPath = n;
}
try{
ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(newPath + name + ".zip"),BUFFER));
for(int i = 0; i < len; i++){
zip_Folder(new File(path +"/"+ list[i]),zipOut);
}
zipOut.close();
}
catch(FileNotFoundException e){
Log.e("File Not Found", e.getMessage());
}
catch(IOException e){
Log.e("IOException", e.getMessage());
}
}
private void zip_Folder(File file, ZipOutputStream zipOut)throws IOException {
// TODO Auto-generated method stub
String s1 = file.getPath();
Log.d("JWP", "PATH "+s1);
byte data[] = new byte[BUFFER];
int read;
if(file.isFile()){
ZipEntry entry = new ZipEntry(file.getName());
zipOut.putNextEntry(entry);
BufferedInputStream inputStream = new BufferedInputStream(new FileInputStream(file));
while((read = inputStream.read(data,0,BUFFER)) != -1){
zipOut.write(data, 0, read);
}
zipOut.closeEntry();
inputStream.close();
}
else if(file.isDirectory()){
String[] list = file.list();
int len = list.length;
for(int i = 0; i < len; i++)
zip_Folder(new File(file.getPath()+"/"+ list[i]), zipOut);
}
}
여기에 압축을 풀고 코드입니다
공공 무효 createZipFolder (문자열 경로) .. 여기
내가 wrriten 한 코드입니다 ... 내가 그것을 분류하는 도와주세요. ..공개 무효 extractZipFiles (문자열 ZipFile를 문자열 DIR) {
Log.d("JWP", "ZIP FILE :"+zipFile+ " DIR :"+dir);
byte data[] = new byte[BUFFER];
String name,path,zipDir;
ZipEntry entry;
ZipInputStream zipInputStream;
if(!(dir.charAt(dir.length() - 1) == '/')){
dir += "/";
}
if(zipFile.contains("/")){
path = zipFile;
name = path.substring(path.lastIndexOf("/") + 1, path.length() - 4);
zipDir = dir + name + "/";
}
else{
path = dir + zipFile;
name = path.substring(path.lastIndexOf("/") + 1, path.length() - 4);
zipDir = dir + name + "/";
}
new File(zipDir).mkdir();
try{
zipInputStream = new ZipInputStream(new FileInputStream(path));
while((entry = zipInputStream.getNextEntry()) != null){
String buildDir = zipDir;
String dirs[] = entry.getName().split("/");
if(dirs != null && dirs.length > 0){
for(int i = 0; i < dirs.length - 1; i++){
buildDir += dirs[i] + "/";
new File(buildDir).mkdir();
}
}
int read = 0;
FileOutputStream out = new FileOutputStream(zipDir + entry.getName());
while((read = zipInputStream.read(data, 0, BUFFER)) != -1){
out.write(data, 0, read);
}
zipInputStream.closeEntry();
out.close();
}
}
catch(FileNotFoundException e){
e.printStackTrace();
}
catch(IOException e){
e.printStackTrace();
}
}
이것을 사용해 보셨습니까 ?? http://www.jondev.net/articles/Unzipping_Files_with_Android_%28Programmatically%29 – Hein
예, 여기에 압축 해제 코드가 있습니다. –