java exception的,Exception抛出

ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(FileName));

ZipEntry entry = null;

while((entry = zipInputStream.getNextEntry()) != null){

inputStream = zipInputStream;

outputStream.putNextEntry(entry);

while((readLength = inputStream.read(inputBuffer)) > 0)

{

outputStream.write(inputBuffer, 0, readLength);

}

outputStream.closeEntry();//Exception

}

最后一行的时候会有个Exception抛出

------解决方法--------------------------------------------------------

你的写法很乱,我给你发一个压缩代码,一个解压缩你参考一下:

1,unZip:

ZipInputStream zipInputStream = new ZipInputStream(inputStream);

while (true) {

ZipEntry nextEntry = zipInputStream.getNextEntry();

if (nextEntry == null) {

break;

}

if (nextEntry.isDirectory()) {

throw new DSWFException( "上传压缩包中包含文件夹! ");

}

String name = nextEntry.getName();

......

}

2,zip:

File newZip = new File( "压缩文件名.zip ");

FileOutputStream out = new FileOutputStream(newZip);

ZipOutputStream zipOutputStream = new ZipOutputStream(out);

File []inputFiles = rootFile.listFiles();//要压缩的文件列表

for (int k = 0; k < inputFiles.length;k ++) {

ZipEntry zipEntry = new ZipEntry(inputFiles[k].getName());

zipOutputStream.putNextEntry(zipEntry);

FileInputStream fis = new FileInputStream(inputFiles[k]);

while (true) {

int b = fis.read();

if (b == -1) {

break;

}

zipOutputStream.write(b);

}

fis.close();

zipOutputStream.closeEntry();

}

zipOutputStream.close();

供参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值