Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. public void distinctSort(String inputPath, String outputPath) throws IOException {
  2. Files.lines(Paths.get(inputPath))
  3. .filter(s -> {
  4. try {
  5. Integer.parseInt(s);
  6. return true;
  7. } catch (NumberFormatException nfe) {
  8. return false;
  9. }
  10. })
  11. .map(Integer::parseInt)
  12. .distinct()
  13. .sorted()
  14. .forEachOrdered(s -> {
  15. try {
  16. RandomAccessFile out = new RandomAccessFile(outputPath, "rw");
  17. Files.write(Paths.get(outputPath), (s + "\n").getBytes(), StandardOpenOption.APPEND);
  18. } catch (IOException ioe) {
  19. ioe.printStackTrace();
  20. }
  21. });
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement