This week's book giveaway is in the OCP forum.
We're giving away four copies of OCP Java SE 8 Programmer II Exam Study Guide and have Kathy Sierra, Bert Bates, & Elizabeth Robson on-line!
See this thread for details.
Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Trapezoidal rule  RSS feed

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi folks, need help:

I tried running the code for trapezoidal rule. It's my project in Numerical Methods, here's the code:



It cannot be compiled and I always get FileNotFoundException. Found on http://docs.oracle.com/javase/8/docs/api/java/io/FileNotFoundException.html that this will be thrown when a file with the pathname does not exist. Please help. Thanks!
 
Bartender
Posts: 2155
46
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch!

It does not compile or it throws an exception at runtime? It can't do both.

How are you running this program? Any parameters? Are you sure you have a file named InpData.txt or with the name passed as parameter?
 
George Maravich
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually it does not compile on Netbeans. Then I get FileNotFoundException. I'm sure that the file name is exactly the same as in the code. Checked it several times. I really can't understand.
 
Ranch Hand
Posts: 98
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you put the txt file in the directory of your Netbeans project? I don't remember exactly where Netbeans looks for a file (either upon reading or writing), but it most likely is the root of your project.
 
George Maravich
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeah I putted it in the directory of the netbeans project (i.e. the root folder for the textfiles). But, I still have FileNotFoundException issue here. Can I add something in my code that resolves this issue?
 
Rancher
Posts: 1016
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do we know what is the working directory when Netbeans runs a file (project)?
For a quick-and-dirty solution (as when testing or for one-time usage programs) I tend to use absolute file names.
 
Ivan Jozsef Balazs
Rancher
Posts: 1016
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

reveals the working directory. In my case during a small test:
C:\Documents and Settings\iván.BALAZS-ASZTALI\Dokumentumok\NetBeansProjects\ZipList

That is, the "root directory" of the given project (and not that of NetBeans).
 
George Maravich
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll try that Ivan hope it works and help me with FileNotFoundException issue with my code... Thanks!
 
Marshal
Posts: 58321
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please explain exactly how you get that particular Exception. Does your code compile?
Please don't use that link for API documentation. Use this link and copy‑and‑paste the individual classes.
 
Campbell Ritchie
Marshal
Posts: 58321
178
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please show us exactly where the file you are looking for is. It must be in a particular location which IJB has already told you about.
 
George Maravich
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here:

C:\Users\GeorgeM\Documents\NetBeansProjects\trapezoidRule\nbproject\textfilespath

Running crazy about this FileNotFoundException for days now
 
Vasilis Souvatzis
Ranch Hand
Posts: 98
1
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take it out of the nbproject folder and put it in trapezoidRule? Haven't worked with files in a long time but I think by default they're supposed to be in your project's root folder...
 
Rancher
Posts: 42975
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As others have advised, you should just use absolute paths and be done with it. Running an app in an IDE simply isn't like running it standalone, so there are limits how far one should go to accommodate that.
 
George Maravich
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's been a week now and I still couldn't solve the FileNotFoundException problem.

What do you mean by absolute path Ulf?
 
Ivan Jozsef Balazs
Rancher
Posts: 1016
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An absolute path name is something like this:

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!