Advertisement
Guest User

even_shittier_java_code

a guest
Dec 12th, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.46 KB | None | 0 0
  1. /**
  2.  * Danasnji labos: napraviti kolekciju elemenata koji sadrze:
  3.  * String broj racuna, Double ukupan iznos racuna te Path racuna.
  4.  *  Preko naredbenog retka upisati neki iznos te u zip mapu imena manjiod<IZNOS>
  5.  * kopirati sve racune ciji je ukupan iznos manji od zadanog.
  6.  */
  7.  
  8. package utorak_zip;
  9.  
  10. import java.io.File;
  11. import java.io.FileOutputStream;
  12. import java.io.IOException;
  13. import java.nio.file.Files;
  14. import java.nio.file.Path;
  15. import java.nio.file.Paths;
  16. import java.util.TreeSet;
  17. import java.util.zip.ZipEntry;
  18. import java.util.zip.ZipOutputStream;
  19.  
  20. public class Program {
  21.     public static void main(String[] args) throws IOException {
  22.         Path source = Paths.get("./racuni");
  23.         MySecondByteReader myReader = new MySecondByteReader();
  24.         if(args.length != 1) {
  25.             System.out.println("Need 1 argument, closing!");
  26.             return;
  27.         }
  28.        
  29.         Double minTotal = Double.parseDouble(args[0]);
  30.         String filename = "manjiod" + args[0] +  ".zip";
  31.        
  32.         try {
  33.             Files.walkFileTree(source, myReader);
  34.             TreeSet<Element> elements = myReader.getElements();
  35.             File zip = new File(filename);
  36.            
  37.             ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zip));
  38.            
  39.             for(Element e : elements) {
  40.                 if(e.getTotal() < minTotal) {
  41.                     ZipEntry entry = new ZipEntry(e.getPath().toString());
  42.                     out.putNextEntry(entry);
  43.                     out.closeEntry();
  44.                 }
  45.             }
  46.  
  47.             out.close();     
  48.                  
  49.              } catch(IOException e) {
  50.                  e.printStackTrace();
  51.              }
  52.         }
  53.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement