您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Java如何压缩文件

2024/5/30 20:45:09发布13次查看
代码如下:
public static void zipfilepip() {    long begintime = system.currenttimemillis();    try(writablebytechannel out = channels.newchannel(new fileoutputstream(zip_file))) {        pipe pipe = pipe.open();        //异步任务        completablefuture.runasync(()->runtask(pipe));        //获取读通道        readablebytechannel readablebytechannel = pipe.source();        bytebuffer buffer = bytebuffer.allocate(((int) file_size)*10);        while (readablebytechannel.read(buffer)>= 0) {            buffer.flip();            out.write(buffer);            buffer.clear();        }    }catch (exception e){        e.printstacktrace();    }    printinfo(begintime);}//异步任务public static void runtask(pipe pipe) {    try(zipoutputstream zos = new zipoutputstream(channels.newoutputstream(pipe.sink()));            writablebytechannel out = channels.newchannel(zos)) {        system.out.println(begin);        for (int i = 0; i < 10; i++) {            zos.putnextentry(new zipentry(i+suffix_file));            filechannel jpgchannel = new fileinputstream(new file(jpg_file_path)).getchannel();            jpgchannel.transferto(0, file_size, out);            jpgchannel.close();        }    }catch (exception e){        e.printstacktrace();    }}
以上就是java如何压缩文件的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product