This week's book giveaway is in the
General Computing
forum.
We're giving away four copies of
Arduino in Action
and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See
this thread
for details.
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Beginning Java
Author
this code is giving file not found exception
deepak bhai
Ranch Hand
Joined: Apr 22, 2011
Posts: 32
posted
Nov 29, 2011 09:11:36
0
public class ReadFile { public int arr [] []; int value; String s; public int[][] readGraph() { int pos1,pos2; BufferedReader reader=null; File file=new File("graphf.txt"); //this line is running fine try{ FileReader fr=new FileReader(file); //this line is giving error :( file not found reader=new BufferedReader(fr); s=reader.readLine(); value=Integer.parseInt(s); arr=new int [value][value]; String [] line=new String[value]; //for inserting zero in all array for (int i=0;i<value;i++){ for(int j=0;j<value;j++){ arr[i][j]=0; } } for(int i=1;i<=value;i++){ s=reader.readLine(); line=s.split(","); pos1=Integer.parseInt(line[0]); for(int j=1;j<line.length;j++){ int n=Integer.parseInt(line [j]); arr[pos1][n]=1; } } } catch(Exception e){ System.out.println("file not found"); e.printStackTrace(); System.out.println(e.getMessage()); } finally{ try{ reader.close(); }catch(Exception e){}; } return arr; }
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32839
4
posted
Nov 29, 2011 09:45:13
1
And why do you think it is throwing such an Exception? More details
here
.
deepak bhai
Ranch Hand
Joined: Apr 22, 2011
Posts: 32
posted
Nov 29, 2011 11:39:44
0
yes i have checked the file accesibility , system have full rights on it .. also i am running my net beans using run as administrator
Ralph Cook
Ranch Hand
Joined: May 29, 2005
Posts: 479
posted
Nov 29, 2011 11:54:07
1
The most likely reason: it is not in the directory where you think it is looking. Use a full file path and see if it still gives you the error.
The second most likely reason: the filename is spelled differently in the program than the file's actual name.
rc
deepak bhai
Ranch Hand
Joined: Apr 22, 2011
Posts: 32
posted
Nov 29, 2011 12:43:04
0
thanks ralph, for your valuable reply
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32839
4
posted
Nov 30, 2011 08:26:33
0
deepak bhai wrote:
. . . using run as administrator
Why? I thought it was regarded as potentially dangerous to run ordinary code as an administrator.
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: this code is giving file not found exception
Similar Threads
travel agent java -- problem when i put the input prompt it does not go to the next promp
travel agent - java writing to file via user input
unable to exit program..
Array vs java.util.ArrayList
getting no such element exception
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter