Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class test123 {
  5. public static void main(String[] args) throws Exception {
  6. if (args.length != 1) {
  7. System.out.println("Usage: java test123 TextFile");
  8. System.exit(1);
  9. }
  10.  
  11. File textFile = new File(args[0]);
  12. if (!textFile.exists()) {
  13. System.out.println("The file " + args[0] + " does not exist.");
  14. System.exit(2);
  15. }
  16.  
  17. List<String> list = new ArrayList<>();
  18.  
  19. try (
  20. Scanner input = new Scanner(textFile);
  21. ) {
  22. while (input.hasNext()) {
  23. String[] array = input.nextLine().split(" ");
  24. for (int i = 0; i < array.length; i++) {
  25. if (array[i].length() > 0 &&
  26. Character.isLetter(array[i].charAt(0))) {
  27. list.add(array[i]);
  28. }
  29. }
  30. }
  31. }
  32. Collections.sort(list);
  33.  
  34. System.out.println(list);
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement