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!

This article addresses the Windows "INVALID_DATA_ACCESS_TRAP" (0x00000004) error, a critical BSOD. It explores common causes like faulty drivers, hardware malfunctions (RAM, hard drive), software conflicts, overclocking, and malware. Trou

This article provides practical tips for maintaining ENE SYS systems. It addresses common issues like overheating and data corruption, offering preventative measures such as regular cleaning, backups, and software updates. A tailored maintenance s

Article discusses editing Windows Registry, precautions, backup methods, and potential issues from incorrect edits. Main issue: risks of system instability and data loss from improper changes.

Article discusses managing Windows services for system health, including starting, stopping, restarting services, and best practices for stability.

This article identifies five common pitfalls in ENE SYS implementation: insufficient planning, inadequate user training, improper data migration, neglecting security, and insufficient testing. These errors can lead to project delays, system failures

What does the drive health warning in Windows Settings mean and what should you do when you receive the disk warning? Read this php.cn tutorial to get step-by-step instructions to cope with this situation.

This article identifies ene.sys as a Realtek High Definition Audio driver component. It details its function in managing audio hardware, emphasizing its crucial role in audio functionality. The article also guides users on verifying its legitimacy

This article addresses the failure of the Windows asio.sys audio driver. Common causes include corrupted system files, hardware/driver incompatibility, software conflicts, registry issues, and malware. Troubleshooting involves SFC scans, driver upda


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
