Home Computer Tutorials Computer Knowledge A file compression program written in JAVA

A file compression program written in JAVA

Jan 24, 2024 pm 12:09 PM

A file compression program written in JAVA

A JAVA ZIP compression program

In fact, it is nothing more than compressing the file addresses you specify one by one according to the recursive method.

out.putNextEntry(new ZipEntry(XXX)); Here is the content you want to compress,

For example: if it is a folder, then out.putNextEntry(new ZipEntry (folder name "/"));

If it is the content in the folder, then: out.putNextEntry(new ZipEntry (folder name "/" folder name));

Actually, there are still some problems with the program above, and it cannot meet your expectations. Let me help you modify it:

The for loop should be modified to this:

for (int i = 0; i

javaCompress File into zip

ZipOutputStream zos = new ZipOutputStream(new FileOutputStream("d:\\test.zip"));

String test1="test1";

String test2="test2";

byte[] bytes1 = test1.getBytes("UTF-8");

byte[] bytes2 = test2.getBytes("UTF-8");

ZipEntry z1 = new ZipEntry("test1.txt");

zos.putNextEntry(z1);

zos.write(bytes1);

ZipEntry z2 = new ZipEntry("text2.txt");

zos.putNextEntry(z2);

zos.write(bytes2);

zos.closeEntry();

zos.close();

//The stream can be obtained by yourself

//Java default package does not support Chinese (garbled characters)

//Use apache's ZipOutputStream for zip compression

Can this solve your problem?

The above is the detailed content of A file compression program written in JAVA. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004) How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004) Mar 11, 2025 am 11:26 AM

How to Solve Windows Error Code "INVALID_DATA_ACCESS_TRAP" (0x00000004)

ENE SYS Maintenance: Tips and Tricks to Keep Your System Running Smoothly ENE SYS Maintenance: Tips and Tricks to Keep Your System Running Smoothly Mar 07, 2025 pm 03:09 PM

ENE SYS Maintenance: Tips and Tricks to Keep Your System Running Smoothly

5 Common Mistakes to Avoid During ENE SYS Implementation 5 Common Mistakes to Avoid During ENE SYS Implementation Mar 07, 2025 pm 03:11 PM

5 Common Mistakes to Avoid During ENE SYS Implementation

which application uses ene.sys which application uses ene.sys Mar 12, 2025 pm 01:25 PM

which application uses ene.sys

why won't driver asio.sys load why won't driver asio.sys load Mar 10, 2025 pm 07:58 PM

why won't driver asio.sys load

Discover How to Fix Drive Health Warning in Windows Settings Discover How to Fix Drive Health Warning in Windows Settings Mar 19, 2025 am 11:10 AM

Discover How to Fix Drive Health Warning in Windows Settings

how to stop cont open asio.sys message windows 11 how to stop cont open asio.sys message windows 11 Mar 10, 2025 pm 07:54 PM

how to stop cont open asio.sys message windows 11

How do I edit the Registry? (Warning: Use with caution!) How do I edit the Registry? (Warning: Use with caution!) Mar 21, 2025 pm 07:46 PM

How do I edit the Registry? (Warning: Use with caution!)

See all articles