Cypher121

How not to read ints from file

Oct 15th, 2015
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. import java.io.File;
  2. import java.io.PrintWriter;
  3. import java.nio.file.Files;
  4. import java.nio.file.Paths;
  5. import java.util.Arrays;
  6. import java.util.stream.IntStream;
  7.  
  8. public class Main {
  9.  
  10.     public static void main(String[] args) throws Exception {
  11.         PrintWriter a;
  12.         (a = new PrintWriter(new File("a.out"))).println(Arrays.stream(
  13.                 new String(Files.readAllBytes(Paths.get("a.in"))).split("[\\D]+")).flatMapToInt(n -> IntStream.of(Integer.parseInt(n))).sum());
  14.         a.close();
  15.     }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment