| Author |
cannot read file..
|
nani aman
Ranch Hand
Joined: Sep 22, 2004
Posts: 33
|
|
hello.. i couldn't read a file. There is no error but it keep give the exception statement. Please help me to figure this out. This is the code : public class TesTing2 { public TesTing2(){ try{ BufferedReader file = new BufferedReader(new FileReader("input.txt")); StringTokenizer inputStream; String s; while ((s = file.readLine()) != null) { inputStream = new StringTokenizer (s); char[] keep = new char[s.length()]; for(int i =0;inputStream.hasMoreTokens()==true;i++) { inputStream.nextToken(); testing(); keep = s.toCharArray(); elementCheck(keep); System.out.println("All done!" + keep); } } } catch (Exception file){ System.out.println("Cannot open file"); } } Please help me. Thank you.
|
 |
Alex Iordanoglou
Greenhorn
Joined: Oct 21, 2004
Posts: 6
|
|
Hi there, Is your class in a package? I run your code (except the part that you dont include), and I did initially get a FileNotFoundException (by the way, the catch clause would catch anything, it might be a good idea at least to print the stack trace of the exception...) when I first tried to run it. The problem was that I had put the class in a package, and input.txt was in the same directory as the class... but since I was running from one directory "up", it could not find the file... Once I put the input.txt in the same directory from where I was running, there was no problem... Hope it helps...
|
 |
Arnaud Burlet
Ranch Hand
Joined: Oct 08, 2004
Posts: 31
|
|
Of course it gives no error when you hide the error ! The description of the error is inside the Exception, just print it ... replace by and see what is your problem ! Arnaud
|
 |
Parveen Aggarwal
Greenhorn
Joined: Jun 08, 2004
Posts: 7
|
|
Hi... Yaar i think that u should specify the file directory (in which your txt file is present)in classpath settings ... aftre that it will going to work... If it still gives problem please let me know... Cheers!! Parveen
|
 |
nani aman
Ranch Hand
Joined: Sep 22, 2004
Posts: 33
|
|
The exception e is work. It is not an error opening file but an array over bound. Thank a lot friends. [ October 22, 2004: Message edited by: nani aman ]
|
 |
 |
|
|
subject: cannot read file..
|
|
|