java解压缩文件代码 java实现解压缩( 二 )


}else{
zipFileCount++;
}
fileCount++;
}
return fileCount;
}catch(IOException e){
e.printStackTrace();
return -1;
}
}
/**
*读取zip文件清单函数
*参数:File类
*返回值:文件清单数组
*/
public String[] getFileList(String infileA){
try{
ZipInputStream AzipInFile = new ZipInputStream(new FileInputStream(infileA));
//创建数组对象
FileNameArray = new String[(int)getFilFoldCount(infileA)];
//将文件名清单传入数组
int i = 0;
while ((entry = AzipInFile.getNextEntry()) != null){
FileNameArray[i++] = entry.getName();
}
return FileNameArray;
}catch(IOException e){
e.printStackTrace();
return null;
}
}
/**
*创建文件函数
*参数:File类
*返回值:如果创建成功返回0,否则返回-1
*/
public long writeFile(String outFileA,byte[] dataByte){
try{
if (initOutStream(outFileA) == 0){
writeData.write(dataByte);
fileDataOut.close();
return 0;
}else{
fileDataOut.close();
return -1;
}
}catch(IOException e){
e.printStackTrace();
return -1;
}
}
/**
*读取文件内容函数
*参数:File类
*返回值:如果读取成功则返回读取数据的字节数组 , 如果失败则返回空值
*/
protected byte[] readFile(ZipEntry entryA,ZipInputStream zipFileA){
try{
long entryFilelen;
if (initInStream(zipFileA) == 0){
if ((entryFilelen = entryA.getSize()) = 0){
byte[] entryFileData = https://www.04ip.com/post/new byte[(int)entryFilelen];
readData.readFully(entryFileData,0,(int)entryFilelen);
return entryFileData;
}else{
return null;
}
}else{
return null;
}
}catch(IOException e){
e.printStackTrace();
return null;
}
}
/**
*创建目录函数
*参数:要创建目录的路径
*返回值:如果创建成功则返回0,否则返回-1
*/
public long createFolder(String dir){
File file = new File(dir);
if (file.mkdirs()) {
return 0;
}else{
return -1;
}
}
/**
*删除文件
*参数:要删除的文件
*返回值:如果删除成功则返回0,要删除的文件不存在返回-2
*如果要删除的是个路径则返回-3 , 删除失败则返回-1
*/
public long deleteFile(String Apath) throws SecurityException {
File file = new File(Apath.trim());
//文件或路径不存在
if (!file.exists()){
return -2;
}
//要删除的是个路径
if (!file.isFile()){
return -3;
}
//删除
if (file.delete()){
return 0;
}else{
return -1;
}
}
/**
*删除目录
*参数:要删除的目录
*返回值:如果删除成功则返回0 , 删除失败则返回-1
*/
public long deleteFolder(String Apath){
File file = new File(Apath);
//删除
if (file.delete()){
return 0;
}else{
return -1;
}
}
/**
*判断所要解压的路径是否存在同名文件
*参数:解压路径
*返回值:如果存在同名文件返回-1,否则返回0
*/
public long checkPathExists(String AreleasePath){
File file = new File(AreleasePath);
if (!file.exists()){
return 0;
}else{
return -1;
}
}
/**
*删除zip中的文件
*参数:文件清单数组 , 释放路径
*返回值:如果删除成功返回0,否则返回-1
*/
protected long deleteReleaseZipFile(String[] listFilePath,String releasePath){

推荐阅读