title: How to bubblesort/alphabetize(using .compareTo) a .txt file that the user enters? [Java]
body: <p>Alright. I have spent hours trying to solve this but all I get is a plethora of errors. What I am trying to make is a program that allows for someone to enter a .txt file (this is not my issue) and to have it alphabetize itself by using some sort of a for-loop and then display itself to the user (I also don't know how to print my .txt file and show it to the user). This is my code (don't laugh, I know it is horrendous). I can code fairly well but for some reason this specific area is giving me loads of issues.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import java.util.Scanner;
  import java.io.File;
  
  public class AlphaSortingBubble {
  
  
    public static void main(String[] args) {
      Scanner keyboard = new Scanner(System.in);
      System.out.println("Enter file you want to alphabetize");
      String list = keyboard.nextLine();
      Scanner infile = null;
      try {
        infile = new Scanner(new File(list));
        System.out.println("File Found: " + list);
      } catch (Exception e) {
        System.out.println("Error: file not found");
        System.exit(0);
      }
      List &lt; String &gt; myList = new ArrayList &lt; String &gt; (Arrays.asList(list.split(",")));
      sortStringBubble(myList);
      for (int k = 0; k &lt; 4; k++)
        System.out.println(myList[k]);
    }
  
  
    public static void sortStringBubble(String x[]) {
      int j;
      boolean flag = true; // will determine when the sort is finished
      String temp;
  
      while (flag) {
        flag = false;
        for (j = 0; j &lt; x.length - 1; j++) {
          if (x[j].compareToIgnoreCase(x[j + 1]) &gt; 0) { // ascending sort
            temp = x[j];
            x[j] = x[j + 1]; // swapping
            x[j + 1] = temp;
            flag = true;
          }
        }
      }
    }
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>Yeah, its pretty bad. I will be in debt to anyone that can help.</p>