SotirovG

SortLines_06

Sep 24th, 2021
836
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package JavaProModule.JavaAdvanced.StreamsAndDirectoriesLab;
  2.  
  3. import java.io.FileOutputStream;
  4. import java.io.IOException;
  5. import java.io.PrintStream;
  6. import java.io.PrintWriter;
  7. import java.nio.file.Files;
  8. import java.nio.file.Path;
  9. import java.util.Collections;
  10. import java.util.List;
  11.  
  12. public class SortLines_06 {
  13.     public static void main(String[] args) throws IOException {
  14.  
  15.         Path inputPath = Path.of("D:\\Java\\IntelliJProjects\\JavaAllModules" +
  16.                 "\\src\\JavaProModule\\JavaAdvanced\\StreamsAndDirectoriesLab" +
  17.                 "\\FilesAndDirectoriesResourcesLab\\input.txt");
  18.  
  19.         String outputPath = "D:\\Java\\IntelliJProjects\\JavaAllModules\\" +
  20.                 "src\\JavaProModule\\JavaAdvanced\\" +
  21.                 "StreamsAndDirectoriesLab\\SortLines_06.txt";
  22.         //FileOutputStream output = new FileOutputStream(outputPath);
  23.  
  24.         PrintWriter writer = new PrintWriter(outputPath);
  25.  
  26.  
  27.         List<String> lines = Files.readAllLines(inputPath);
  28.         Collections.sort(lines);
  29.         for (String line : lines) {
  30.             writer.println(line.trim());
  31.         }
  32.         writer.close();
  33.  
  34.  
  35.     }
  36. }
  37.  
RAW Paste Data