Guest User

Untitled

a guest
Jan 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. package com.javarush.task.task18.task1827;
  2.  
  3. /*
  4. Прайсы
  5. */
  6.  
  7. import java.io.*;
  8. import java.nio.file.Files;
  9. import java.nio.file.Paths;
  10. import java.util.Scanner;
  11. import java.util.concurrent.atomic.AtomicInteger;
  12.  
  13. public class Solution {
  14. public static void main(String[] args) throws Exception {
  15. String fileName = new Scanner(System.in).nextLine();
  16. if (args.length != 0) {
  17.  
  18. AtomicInteger maxId = new AtomicInteger(0);
  19.  
  20. Files.lines(Paths.get(fileName))
  21. .filter(value -> !value.isEmpty())
  22. .map(s -> s.substring(0, 8).trim())
  23. .mapToInt(Integer::parseInt)
  24. .max()
  25. .ifPresent(maxId::set);
  26. FileOutputStream outputStream = new FileOutputStream(fileName, true);
  27. outputStream.write(String.format("\n%-8s%-30s%-8s%-4s", maxId.incrementAndGet(), args[1], args[2], args[3]).getBytes());
  28. new FileInputStream(fileName).close();
  29. outputStream.close();
  30. }
  31. }
  32. }
Add Comment
Please, Sign In to add comment