By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,262 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,262 IT Pros & Developers. It's quick & easy.

Problem finding file with File Input

P: 3
I'm attempting to make my first program that involves file input, but I'm running into problems finding the .txt file.

I placed the file inside the same folder as the rest of the project, but it still doesn't seem to be finding it. Am I doing something wrong?

Expand|Select|Wrap|Line Numbers
  2. try
  3.         {
  4.             in = new Scanner(new File("File Reading.txt"));
  5.             String test = in.nextLine();
  6.             System.out.println(test);
  7.         }
  8.         catch(Exception i)
  9.         {
  10.             System.out.println("Error: " + i.getMessage());
  11.         }

That's the portion of the code that is supposed to read the file. I cut out the declaration of the Scanner in and the rest of the class, but I figured that wouldn't have anything to do with the problem I'm having.
Mar 28 '07 #1
Share this Question
Share on Google+
1 Reply

P: 3
Oh never mind, I figured it out myself.

I still needed to specify the file location in the code.

Feel free to delete this now. :)
Mar 29 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.