Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Danasnji labos: napraviti kolekciju elemenata koji sadrze:
- * String broj racuna, Double ukupan iznos racuna te Path racuna.
- * Preko naredbenog retka upisati neki iznos te u zip mapu imena manjiod<IZNOS>
- * kopirati sve racune ciji je ukupan iznos manji od zadanog.
- */
- package utorak_zip;
- import java.io.File;
- import java.io.FileOutputStream;
- import java.io.IOException;
- import java.nio.file.Files;
- import java.nio.file.Path;
- import java.nio.file.Paths;
- import java.util.TreeSet;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
- public class Program {
- public static void main(String[] args) throws IOException {
- Path source = Paths.get("./racuni");
- MySecondByteReader myReader = new MySecondByteReader();
- if(args.length != 1) {
- System.out.println("Need 1 argument, closing!");
- return;
- }
- Double minTotal = Double.parseDouble(args[0]);
- String filename = "manjiod" + args[0] + ".zip";
- try {
- Files.walkFileTree(source, myReader);
- TreeSet<Element> elements = myReader.getElements();
- File zip = new File(filename);
- ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip));
- for(Element e : elements) {
- if(e.getTotal() < minTotal) {
- ZipEntry entry = new ZipEntry(e.getPath().toString());
- out.putNextEntry(entry);
- out.closeEntry();
- }
- }
- out.close();
- } catch(IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement