A file compression program written in JAVA
Jan 24, 2024 pm 12:09 PMA 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!

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

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

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

5 Common Mistakes to Avoid During ENE SYS Implementation

Discover How to Fix Drive Health Warning in Windows Settings

how to stop cont open asio.sys message windows 11

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