Hi, I'm writing a program that reverses the words of a text file using the LinkedList structure. Unfortunately, I have received the following error:
java.util.Scanner[delimiters=\p{javaWhitespace}+][position=30][match valid=false][need input=false][source closed=true][skipped=false][group separator=\,][decimal separator=\.][positive prefix=][negative prefix=\Q-\E][positive suffix=][negative suffix=][NaN string=\Q?\E][infinity string=\Q?\E]
And because of that I'm having difficulty proceeding to the next step. If anyone could point me to the right direction on what to do next, I would greatly appreciate it.
import java.util.*;
import java.io.*;
public class ReverseWords
{
public static void main(String[] args) throws FileNotFoundException
{
Scanner scan = new Scanner (System.in);
File f = new File("doriangray.txt");
System.out.print("Enter file name: ");
Scanner input = new Scanner (new File(scan.nextLine()));
System.out.println();
System.out.println(input);
}
public static LinkedList<String> reverse(LinkedList<String> a)
{
ListIterator<String> order = a.listIterator(a.size());
LinkedList<String> reversed = new LinkedList<String>();
while (order.hasPrevious())
{
reversed.add(order.previous());
}
return reversed;
}
}
The text file contains:
As long as I live, the personality of Dorian Gray will dominate me.