I'm having a hard time getting a loop to work for me. I'm writing a program which parses strings, first trying to read from a text file from command line argument, and if that doesn't work, then parse input from the user. The problem I'm having is copying the text to an Arraylist using the hasNext() method. When using the text file everything works fine, but when I use a scanner(System.in), it blocks waiting for me to input more text forever. Can anybody tell me an easy way to get hasNext to return false under these conditions? Another scanner type maybe? Any help would be greatly appreciated. The example is below.

try {
File inputFile = new File(args[0]);
dataScanner = new Scanner(inputFile);
}
catch (IOException e) {
System.out.println("IO exception thrown");
System.out.println("Data must be input manually");
dataScanner = new Scanner(System.in);
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("No input found, Data must be input manually");
dataScanner = new Scanner(System.in);
}

ArrayList<String> stringData = new ArrayList<String>();

int line = 0;
**********************************************************************
while (dataScanner.hasNext()) {

stringData.add(line, dataScanner.next());
System.out.println(stringData.get(line));
line++;

}
**********************************************************************

System.out.println("Loop finished!");
//dataScanner.close();