当前位置:网站首页 > R语言数据分析 > 正文

zipentry(zipentry 编码)



展开全部

ZipEntry 类是java.util.zip包下的一个类,

ZipEntry 类用于表示 ZIP 文件条e58685e5aeb6230目。

利用这个类压缩和解压zip文件

具体压缩的例子如下: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.ZipOutputStream;

/

* 压缩程序

* @author young

*

*/

public class SingleFileZip {

public static void main(String[] args) {

File file = new File("e:/test.txt");

FileInputStream fis = null;

ZipOutputStream zos = null;

try {

fis = new FileInputStream(file);

zos = new ZipOutputStream(new FileOutputStream("e:/my.zip"));

// 创建压缩文件中的条目

ZipEntry entry = new ZipEntry(file.getName());

// 将创建好的条目加入到压缩文件中

zos.putNextEntry(entry);

// 写入当前条目所对应的具体内容

byte[] buff = new byte[1024];

int len = 0;

while ((len = fis.read(buff)) != -1) {

zos.write(buff, 0, len);

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

fis.close();

zos.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

解压例子如下:import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.util.zip.ZipEntry;

import java.util.zip.ZipFile;

import java.util.zip.ZipInputStream;

/

* 解压程序

* @author young

*

*/

public class SingleFileUnZip {

public static void main(String[] args) {

FileOutputStream fos = null;

ZipInputStream zis = null;

InputStream is = null;

try {

ZipFile zf = new ZipFile("e:/my.zip");

zis = new ZipInputStream(new FileInputStream("e:/my.zip"));

fos = new FileOutputStream("e:/unzip.txt");

// 从压缩文件中获取一个条目

ZipEntry entry = zis.getNextEntry();

// 获得该条目对象的数据流

is = zf.getInputStream(entry);

byte[] buff = new byte[1024];

int len = 0;

while ((len = is.read(buff)) != -1) {

fos.write(buff, 0, len);

}

} catch (FileNotFoundException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} finally {

try {

is.close();

zis.close();

fos.close();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

}

}

到此这篇zipentry(zipentry 编码)的文章就 介绍到这了,更多相关内容请继续浏览下面的相关 推荐文章,希望大家都能在编程的领域有一番成就!

版权声明


相关文章:

  • vcoros是什么意思(vios是什么意思?)2026-04-20 16:18:04
  • Tornadoes听力原文(to earn profits only听力答案)2026-04-20 16:18:04
  • 电脑剪辑软件(电脑剪辑软件pr全称)2026-04-20 16:18:04
  • entreat翻译(entirety翻译)2026-04-20 16:18:04
  • srore是什么意思中文(shorer是什么意思译)2026-04-20 16:18:04
  • word文件对比查重(word两篇文章对比查重)2026-04-20 16:18:04
  • ldr指令(ldr指令的功能)2026-04-20 16:18:04
  • termux启动kali(termux启动ubuntu命令)2026-04-20 16:18:04
  • chronyc(chrony配置ntp服务器)2026-04-20 16:18:04
  • yuv420和rgb哪个好(yuv420跟rgb有什么区别)2026-04-20 16:18:04
  • 全屏图片