DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Java (http://www.daniweb.com/forums/forum9.html)
-   -   Help with Exception... (http://www.daniweb.com/forums/thread142956.html)

Minimandz Aug 29th, 2008 9:02 am
Help with Exception...
 
Please could sum1 help me with this:

I'm trying to read text from a file using the Scanner class and i'm not sure y its not throwing the FileNotFound Exception

try
{
Scanner sc = new Scanner (new File ("Food.txt"));
wordList[num] = sc.next();

while(sc.hasNext())
{
wordList[num] = sc.next();
System.out.println(wordList[num]);
num++;
}
sc.close();

}
catch ( FileNotFoundexception f)
{
System.out.println("Cannot find the file");
}

:icon_question:

javaAddict Aug 29th, 2008 9:09 am
Re: Help with Exception...
 
Probably because the file does not exist.
And you could use BufferedReader for reading from file.

Minimandz Aug 29th, 2008 9:12 am
Re: Help with Exception...
 
I found what i did wrong, bt thank u 4 th help


All times are GMT -4. The time now is 12:58 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC