JAVA输出文件为null,java – 提取.zip文件时,ZipInputStream getNextEntry为null

我正在尝试提取.zip文件,我正在使用此代码:

String zipFile = Path + FileName;

FileInputStream fin = new FileInputStream(zipFile);

ZipInputStream zin = new ZipInputStream(fin);

ZipEntry ze = null;

while ((ze = zin.getNextEntry()) != null) {

UnzipCounter++;

if (ze.isDirectory()) {

dirChecker(ze.getName());

} else {

FileOutputStream fout = new FileOutputStream(Path

+ ze.getName());

while ((Unziplength = zin.read(Unzipbuffer)) > 0) {

fout.write(Unzipbuffer, 0, Unziplength);

}

zin.closeEntry();

fout.close();

}

}

zin.close();

但问题是,在调试时,当代码到达while(!= null)部分时,zin.getNextEntry()始终为null,因此它不会提取任何内容.

.zip文件是150kb ..我该如何解决这个问题?

.zip存在

我用来编写.zip的代码:

URL=intent.getStringExtra("DownloadService_URL");

FileName=intent.getStringExtra("DownloadService_FILENAME");

Path=intent.getStringExtra("DownloadService_PATH");

File PathChecker = new File(Path);

try{

if(!PathChecker.isDirectory())

PathChecker.mkdirs();

URL url = new URL(URL);

URLConnection conexion = url.openConnection();

conexion.connect();

int lenghtOfFile = conexion.getContentLength();

lenghtOfFile/=100;

InputStream input = new BufferedInputStream(url.openStream());

OutputStream output = new FileOutputStream(Path+FileName);

byte data[] = new byte[1024];

long total = 0;

int count = 0;

while ((count = input.read(data)) != -1) {

output.write(data, 0, count);

total += count;

notification.setLatestEventInfo(context, contentTitle, "جاري تحميل ملف " + FileName + " " + (total/lenghtOfFile), contentIntent);

mNotificationManager.notify(1, notification);

}

output.flush();

output.close();

input.close();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值