Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package zipowanie;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
- /**
- * Program zapisuje wiele plików do jednego archiwum zip
- */
- public class JedenZipWielePlikowZipowanie
- {
- public static void main(String[] argumenty)
- {
- int i = 0;
- try(FileOutputStream fos = new FileOutputStream("zip_wiele_plikow.zip"))
- {
- try(ZipOutputStream zos = new ZipOutputStream(fos))
- {
- for(i = 0; i<5; i++)
- {
- try(FileInputStream fis = new FileInputStream("anime1.jpg"))
- {
- ZipEntry ze = new ZipEntry(Integer.toString(i) + ".jpg");
- zos.putNextEntry(ze);
- byte[] buffer = new byte[1024];
- int c;
- while(( c = fis.read(buffer, 0, 1024)) != -1)
- {
- zos.write(buffer, 0, c);
- }
- zos.closeEntry();
- System.out.println("Zapis pliku " + Integer.toString(i) + ".jpg zakonczony!");
- }
- }
- }
- }
- catch(IOException ex)
- {
- System.out.println("Nie znaleziono pliku!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement