I can't find why this is not working. Here's my code, and then the error.
import java.util.*; import java.io.*; public class CordreyLab6 { public static void main(String[] args) throws IOException { // get user input for file name Scanner console = new Scanner(System.in); // for user input of file name System.out.println("Please enter a file name: "); String userFile = console.nextLine(); // read file and pass to process method Scanner input = new Scanner(new File (userFile)); processFile(input, console); }// end main
The error is:
Please enter a file name:
Lab6Input.txt
Exception in thread "main" java.io.FileNotFoundException: Lab6Input.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at java.util.Scanner.<init>(Unknown Source)
at CordreyLab6.CordreyLab6.main(CordreyLab6.java:17)
I've put copies of the text file in all the folders I think I could be looking in- the class folder, the c:\root, the src folder, under the sink. I wish I knew what folders and files were created when Eclipse creates a java program. Obviously there is quite a bit more going on than just the source code folder. I don't know where the program is expecting to find the file, so I'm just guessing on where to put it. I suspect there is a better way.
Thank you so much for the help!