| | |
File Not Found Exception
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Apr 2009
Posts: 10
Reputation:
Solved Threads: 0
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.
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.
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
Are you sure about that explanation mark "!" in your file path string?
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
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
•
•
Join Date: Apr 2009
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
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
•
•
Join Date: Apr 2009
Posts: 10
Reputation:
Solved Threads: 0
•
•
•
•
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.
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.
![]() |
Similar Threads
- Exception in thread "main" java.lang.NoClassDefFoundError: Invaders Error (Java)
- XML file not found for parser? (Java)
- JDBC Driver for SQL Server 2005, Class not found Exception (Java)
- sourcing a python config file? (Python)
- system crashes,gets slow, and network gets down,Hijacklog file pvded (Viruses, Spyware and other Nasties)
- General Protection Exception Error Please Help! (C++)
Other Threads in the Java Forum
- Previous Thread: prime numbers
- Next Thread: How to detect circle in a directed graph?
| Thread Tools | Search this Thread |
android api applet application array arrays automation awt bidirectional binary birt bluetooth busy_handler(null) calculator chat class classes client code columns component constructor database designadrawingapplicationusingjavajslider draw eclipse editor error errors event eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress input integer intellij j2me java javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia link linux list loop map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads time tree unlimited utility webservices windows






