I'm Trying to create a code that takes a text file and puts it in alphabetical order. To do this I was trying to read the file and the add each word into an array. I have an idea of how to go about doing this but don't know exactly. Here is what I have so far:
import java.io.*;
import java.util.Scanner;
public class assignment4 {
public static void main(String[] args) throws IOException {
if (args.length == 1){
createArray(args[0]);
System.exit(0);
}
}
public static String createArray(String fileName) {
File testFile = new File(fileName);
Scanner inputFile = new Scanner(testFile);
if (!testFile.exists()){
System.out.println("File Doesn't Exist");
System.exit(0);
}
String[] words;
while(inputFile.hasNext()){
for (int i=0;i<inputFile.length();i++){
words[i] = inputFile.nextLine();
}
}
return words[0];
}
}
I know the majority is probably completely wrong but I'm so confused been working on this for 4 hours now...