File Not Found Exception

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Apr 2009
Posts: 10
Reputation: ippomarley is an unknown quantity at this point 
Solved Threads: 0
ippomarley ippomarley is offline Offline
Newbie Poster

File Not Found Exception

 
0
  #1
Apr 4th, 2009
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import java.io.*;
class ll{


public static void main(String[] a) {


FileReader fr;
try {
fr = new FileReader (new File("C:\\University Study\\Component Engineering\\Assignments\\Assignment !\\yourFile.txt"));
BufferedReader br = new BufferedReader (fr);
String line = br.readLine();
while (line != null) {
System.out.println(line);
line = br.readLine();
}
br.close();

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}




}
}

The text file and the class are in the same folder and even when i specified the location I still get this exception. It's not a compile error it's a runtime error. I've tried to be as specific as i can but this is my first time posting.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 26
Reputation: hiraksarkardg has a little shameless behaviour in the past 
Solved Threads: 2
hiraksarkardg hiraksarkardg is offline Offline
Light Poster

Re: File Not Found Exception

 
0
  #2
Apr 4th, 2009
Most probably, your file location is wrong. It might be "Assignment 1".
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,247
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 540
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: File Not Found Exception

 
-7
  #3
Apr 4th, 2009
also the filenames are case sensitive, and windows has an annoying habit of naming things name.txt.txt
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 1,682
Reputation: javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all javaAddict is a name known to all 
Solved Threads: 227
Featured Poster
javaAddict's Avatar
javaAddict javaAddict is offline Offline
Posting Virtuoso

Re: File Not Found Exception

 
0
  #4
Apr 4th, 2009
Try "right" clicking on the file and select "Properties". You will find the exact location and file name to use at your code
Check out my New Bike at my Public Profile at the "About Me" tab
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,212
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 489
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: File Not Found Exception

 
0
  #5
Apr 4th, 2009
Are you sure about that explanation mark "!" in your file path string?
fr = new FileReader (new File("C:\\University Study\\Component Engineering\\Assignments\\Assignment !\\yourFile.txt"));
Also if you just learning to work with files try to keep your file in same folder as your compiled program so then you do not need to call absolute path as above and can simple use relative just yourFile.txt

PS: You class name doesn't have proper name in according to recommended naming conventions which for class says the first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 10
Reputation: ippomarley is an unknown quantity at this point 
Solved Threads: 0
ippomarley ippomarley is offline Offline
Newbie Poster

Re: File Not Found Exception

 
0
  #6
Apr 4th, 2009
Originally Posted by peter_budo View Post
Are you sure about that explanation mark "!" in your file path string?
fr = new FileReader (new File("C:\\University Study\\Component Engineering\\Assignments\\Assignment !\\yourFile.txt"));
Also if you just learning to work with files try to keep your file in same folder as your compiled program so then you do not need to call absolute path as above and can simple use relative just yourFile.txt

PS: You class name doesn't have proper name in according to recommended naming conventions which for class says the first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase

Hi, I am sorry it took a while to respond my internet has been playing up, and i had to spend hours on the phone with a guy from my ISP. I tried changing the folder name to just Assignment, not Assignment !, but it did not work, also i tried just writing fr = new FileReader (new File("yourFile.txt")); but it still will not work. here is the error i get at runtime

--------------------Configuration: <Default>--------------------
java.io.FileNotFoundException: yourFile.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at ReadFromFile.main(ReadFromFile.java:14)

Process completed.
i also renamed my class and the class file name as ReadFromFile instead of ll. The java file and the txt file are in the same folder. Please help I am stuck, but i am pretty sure my code is correct.
Last edited by ippomarley; Apr 4th, 2009 at 12:36 pm. Reason: meant to reply everyone
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 10
Reputation: ippomarley is an unknown quantity at this point 
Solved Threads: 0
ippomarley ippomarley is offline Offline
Newbie Poster

Re: File Not Found Exception

 
0
  #7
Apr 4th, 2009
Originally Posted by peter_budo View Post
Are you sure about that explanation mark "!" in your file path string?
fr = new FileReader (new File("C:\\University Study\\Component Engineering\\Assignments\\Assignment !\\yourFile.txt"));
Also if you just learning to work with files try to keep your file in same folder as your compiled program so then you do not need to call absolute path as above and can simple use relative just yourFile.txt

PS: You class name doesn't have proper name in according to recommended naming conventions which for class says the first letter should be capitalized, and if several words are linked together to form the name, the first letter of the inner words should be uppercase

Hi, I am sorry it took a while to respond my internet has been playing up, and i had to spend hours on the phone with a guy from my ISP. I tried changing the folder name to just Assignment, not Assignment !, but it did not work, also i tried just writing fr = new FileReader (new File("yourFile.txt")); but it still will not work. here is the error i get at runtime

--------------------Configuration: <Default>--------------------
java.io.FileNotFoundException: yourFile.txt (The system cannot find the file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileReader.<init>(FileReader.java:55)
at ReadFromFile.main(ReadFromFile.java:14)

Process completed.
i also renamed my class and the class file name as ReadFromFile instead of ll. The java file and the txt file are in the same folder. Please help I am stuck, but i am pretty sure my code is correct.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,247
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 540
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: File Not Found Exception

 
-7
  #8
Apr 4th, 2009
What OS are you using? do you actually have read/write permissions on the file?
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 10
Reputation: ippomarley is an unknown quantity at this point 
Solved Threads: 0
ippomarley ippomarley is offline Offline
Newbie Poster

Re: File Not Found Exception

 
0
  #9
Apr 4th, 2009
Originally Posted by jbennet View Post
also the filenames are case sensitive, and windows has an annoying habit of naming things name.txt.txt
Thank you, you were right windows name it yourfile.txt.txt
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,247
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 540
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: File Not Found Exception

 
-7
  #10
Apr 4th, 2009
no problem. If its xp go into my computer -> tools -> folder options and uncheck the box for "hide extensions for known filetypes" - its called something like that . From now on it will always show the extensions.
Last edited by jbennet; Apr 4th, 2009 at 1:30 pm.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC