daily pastebin goal
43%
SHARE
TWEET

Untitled

a guest Jan 23rd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top