| | |
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 |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game gameprogramming givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing system test textfields threads time title tree tutorial-sample ubuntu update windows working






