0

I'm new to java and would appreciate it if someone could give me some help. Thanks in advance.

I am trying to take a filename from the command line and output that file sorted (from my Heap.java) and print it out one word per line.

Here is what I have:

public class HeapSort {

public static void main(String[] args) throws IOException {
  //public static void main(String[] args)  {   


    // Declare and instantiate a new ArrayList object
       ArrayList<String> data = new ArrayList<String>(); 

    //Declare the input file names
      String inFile = "data2415.txt";

     Scanner sc = new Scanner(new File(args[0]));

      if (0 < args.length){
         String filename = args[0];
          File file = new File(filename);
      }

        //h = reader.readLine();

      while (sc.hasNext()) data.add(sc.next());

      }


}
Paradox
  • 4,602
  • 12
  • 44
  • 88

1 Answers1

0

What about

  List<String> resultList = FileUtils.readlines("text.txt");
  Collections.sort(resultList);
  for (String s: resultList)
        System.out.println(s);
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
  • Question says *"print it out one **word** per line"*. This is backed by the code, which uses `Scanner.next()`, not `nextLine()`. The code in this answer will sort *lines*, not *words*, so it's not the same, though for sorting lines it would be a perfect answer. – Andreas Jun 28 '16 at 14:51