Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

File not found: "The system cannot find the file specified"  RSS feed

 
Robert Insanovation White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to make some operations with a file. I struggle to understand why Apache is throwing this error:
(The system cannot find the file specified)

My file is located in the root directory of the project.

And here is how I indicate the path to it:



Thank you.

Update: If I put the file in the Eclipse folder, it works... But I need it to work if I put it in my project's root folder.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A path with only the file name ONLY works if the file is in the "current" directory.

Not something you should rely on for the server environment. Since the "current directory" is independent of your project root.

Bill
 
Felipe Rego Pinto
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

Does the file in you classpath? If yes, you can try:



Best regards,
Felipe
 
Robert Insanovation White
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody, I resolved this by:



Thank you.
 
Felipe Rego Pinto
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Robert Insanovation White wrote:Hi everybody, I resolved this by:



Thank you.


This might also work.


 
Stefan Evans
Bartender
Posts: 1834
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The getRealPath() method, while useful, isn't your optimal solution here.
What happens when your app is deployed in a jar file? What is the filepath to it then?

If you are trying to load an image from your bundle, then the ServletContext method getResourceAsStream is probably more appropriate;
It is very similar to getRealPath in invoking. The main difference being instead of telling you the path to the resource, it just gives it straight to you.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!