Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Program not finding file in same folder  RSS feed

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have to create a histogram based on grades students received that are in a text file named "midterm.txt.". I've posted what I've come up with so far, but to be honest I don't know if I'm even on the right path because I can't get the program to run to see how it behaves. To explain my thought process with what I have currently, I made several lists with grades and then try to read each integer within the file and match the integer it reads with the int's I defined. If it matches, it will add to that count. Below it I am outputting each count just to see if it's working (except program doesn't run.) If I can confirm that its counting then I'll create a histogram. Also below is my error I get in eclipse.


And the text I get in the console:



 
author & internet detective
Sheriff
Posts: 38050
606
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that Eclipse doesn't have the same opinion of the working directory as you do. Can you try adding this statement to your program?

 
Rum Ham
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:My guess is that Eclipse doesn't have the same opinion of the working directory as you do. Can you try adding this statement to your program?



Okay so I added that and it gave me the path so I added it as




Now I get why it's saying that, I'm just wondering how I can put the path in the file statement without producing an error.

Thanks for your help so far.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 38050
606
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Run,
In Java, backslash is a special character. You have to type backslash twice to escape it. Or you can use a forward slash. Java is smart enough to convert in paths. So either of these would work:

 
Rancher
Posts: 2459
80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hard coding is not ideal. This somewhat clumsy line of code works:

 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!