java.io.FileNotFoundException

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.

[2033 byte] By [beckham12a18a] at [2007-10-2 12:02:42]
# 1

Your code works fine for me. I just changed c:\\Errors.txt to c:\\setup.log because setup.log is a file in my c:\ directory. I did notice that the code had "Errors.txt" but the error you posted says "sunjava.txt."

Use a Command Prompt and "dir c:\" to validate that the file actually exists,

atmguya at 2007-7-13 8:20:42 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...
# 2

> Your code works fine for me. I just changed

> c:\\Errors.txt to c:\\setup.log because setup.log is

> a file in my c:\ directory. I did notice that the

> code had "Errors.txt" but the error you posted says

> "sunjava.txt."

>

> Use a Command Prompt and "dir c:\" to validate that

> the file actually exists,

Thanks for your remind. Actually, "Errors.txt" in the code should be "sunjava.txt". It is because i copied wrong thing when i edit the topic.

In addition, i use dir C:\ to validate which files are really existent and i knew why my program yield error. That is because in my Window XP Home, Hide-file-extension mode is turned on, so just file names are displayed. Actually, "sunjava.txt" is "sunjava.log" although "sunjava.log" is edited using Notepad, so FileNotFoundException is screened.

beckham12a18a at 2007-7-13 8:20:42 > top of Java-index,Developer Tools,Debugging and Profiling Tool APIs...