Advertisement
deyanmalinov

6. Sort Lines

Apr 8th, 2020
322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. package DPM;
  2.  
  3. import java.io.IOException;
  4. import java.nio.file.Files;
  5. import java.nio.file.Path;
  6. import java.nio.file.Paths;
  7. import java.util.Collections;
  8. import java.util.List;
  9. import java.util.stream.Collectors;
  10.  
  11. public class Main {
  12.     public static void main(String[] args) throws IOException {
  13.         String inputPath = "D:\\Coding\\Java\\Softuni\\Java Advanced - January 2019" +
  14.                 "\\04. Java-Advanced-Fiels-and-Directories-Lab\\04. Java-Advanced-" +
  15.                 "Files-and-Streams-Lab-Resources\\input.txt";
  16.         String outputPath = "D:\\Coding\\Java\\Softuni\\Java Advanced - January 2019" +
  17.                 "\\04. Java-Advanced-Fiels-and-Directories-Lab\\04. Java-Advanced-" +
  18.                 "Files-and-Streams-Lab-Resources\\output.txt";
  19.  
  20.         Path path = Paths.get(inputPath);
  21.         Path output = Paths.get(outputPath);
  22.         List<String> lines = Files.readAllLines(path);
  23.         lines = lines.stream().filter(l ->
  24.                 !l.isBlank()).collect(Collectors.toList());
  25.         Collections.sort(lines);
  26.         Files.write(output, lines);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement