| | |
Help with Exception...
Thread Solved
![]() |
•
•
Join Date: Aug 2008
Posts: 4
Reputation:
Solved Threads: 0
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");
}
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");
}
Probably because the file does not exist.
And you could use BufferedReader for reading from file.
And you could use BufferedReader for reading from file.
Check out my New Bike at my Public Profile at the "About Me" tab
![]() |
Similar Threads
- purpose of exception handling 'finally' clause (Java)
- help with sort using Calendar class getting null pointer exception (Java)
- fatal exception OE VXD VFAT (Windows 95 / 98 / Me)
- Exception messages reappears constantly! (Windows NT / 2000 / XP)
- Arithmetic Exceptions and exception-handling statements (Java)
Other Threads in the Java Forum
- Previous Thread: mapping classes
- Next Thread: I need Extract Email from html or doc code
| Thread Tools | Search this Thread |
-xlint actionlistener android api applet application array automation bi binary blackberry block bluetooth character class client code compile compiler component consumer database desktop developmenthelp eclipse error fractal freeze ftp functiontesting game gameprogramming givemetehcodez graphics gui health html hyper ide image int j2me j2seprojects java javac javaee javaprojects jetbrains jni jpanel jtable julia learningresources lego linked linux mac main map method mobile myregfun netbeans nonstatic notdisplaying number online pearl printf problem program project qt researchinmotion rotatetext rsa scanner screen server set singleton sms sort spamblocker sql string swing system textfields thread threads time title tree tutorial-sample update variablebinding windows working xor






