Untitled
unknown
plain_text
5 months ago
1.0 kB
4
Indexable
// Ścieżka do pliku, który chcemy zzipować String sourceFile = "test.eml"; // Ścieżka do pliku wynikowego .zip String zipFileName = "test.zip"; try (FileOutputStream fos = new FileOutputStream(zipFileName); ZipOutputStream zipOut = new ZipOutputStream(fos); FileInputStream fis = new FileInputStream(sourceFile)) { // Dodanie pliku do archiwum ZIP ZipEntry zipEntry = new ZipEntry(sourceFile); zipOut.putNextEntry(zipEntry); byte[] buffer = new byte[1024]; int length; while ((length = fis.read(buffer)) >= 0) { zipOut.write(buffer, 0, length); } zipOut.closeEntry(); System.out.println("Zipping completed: " + zipFileName); } catch (IOException e) { System.err.println("An error occurred while zipping the file: " + e.getMessage()); }
Editor is loading...
Leave a Comment