Didart

Sort Lines

Jan 25th, 2023 (edited)
773
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. package StreamsFilesAndDirectories4;
  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.  
  10. public class SortLines {
  11.     public static void main(String[] args) throws IOException {
  12.  
  13.         String inPath = "input.txt";
  14.         String outPath = "output.txt";
  15.  
  16.       Path input = Paths.get(inPath);
  17.       Path output = Paths.get(outPath);
  18.  
  19.         List<String> lines= Files.readAllLines(input);
  20.         Collections.sort(lines);
  21.         Files.write(output, lines);
  22.     }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment