Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.io.FileNotFoundException

843810Feb 11 2006 — edited Feb 12 2006
import java.io.*;
import java.util.*;

public class WordDisplay {
public static void main(String args[]) throws IOException{
FileReader fr = new FileReader("C:\\Errors.txt");
BufferedReader br = new BufferedReader(fr);
int c;
String content = "";

while((c = br.read()) != -1){
content += (char)c;
}

StringTokenizer stn = new StringTokenizer(content, " ");

while(stn.hasMoreTokens()){
System.out.println(stn.nextToken());
}

fr.close();
br.close();
}
}

I keep wonderring why it was so strange that when i ran the above snippet of code.
The exception is:

java.io.FileNotFoundException: C:\sunjava.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.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at WordDisplay.main(WordDisplay.java:6)


The strange thing is that the file sunjava.txt does exist in C volume. Even when i alterred the
sunjava.txt with other existing *.txt files in C volume, the exception keeps occurring:

java.io.FileNotFoundException: C:\chpst.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.FileInputStream.<init>(FileInputStream.java:66)
at java.io.FileReader.<init>(FileReader.java:41)
at WordDisplay.main(WordDisplay.java:6)
I carefully checked the spelling, and the properties of these files, but the exeption is still there.
However, when i create a new .txt file (such as abc.txt and whatever new files i created), the program works well, no exception comes out.
I cannot work out why it is like that. Anyone can help me explain the case, please.

Thanks a lot.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 12 2006
Added on Feb 11 2006
2 comments
413 views