-1

I have a directoy names images in the assets folder which contain a collection of images. I am trying to access the images in my code, i keep getting file not found exception.

File file = new File("public/images/iowa.jpg");

any idea whats the reason?

user3687679
  • 359
  • 2
  • 16
  • 1
    Maybe the folder is not correct. – Jens Jan 22 '15 at 08:50
  • Try to use full path, like D:/.../public/images/iowa.jpg – drgPP Jan 22 '15 at 08:50
  • Which OS are u using? Have you checked the docs: http://docs.oracle.com/javase/7/docs/api/java/io/File.html – facundofarias Jan 22 '15 at 08:51
  • You have not given the folder/directory structure of where you have stored the image files, and the path of the file containing the above source code to be able to view the path traversal. But please try using the absolute path to the file, then run it again and tell us the result – Peter Jan 22 '15 at 08:52
  • i cant use the full path. i want a relative path so it will work on my local machine and also when i upload the application to some server. – user3687679 Jan 22 '15 at 08:53
  • @user3687679 Check the current working directory your program is running in... – Stephan Jan 22 '15 at 08:55
  • 1
    @ user3687679 Then you can move back to your directory using ../ and if your folder is located one step back from your source code, than the path should look like "../public/images/iowa.jpg" – drgPP Jan 22 '15 at 08:55

2 Answers2

0

As you can read here

This exception will be thrown

when a file with the specified pathname does not exist.

Or

if the file does exist but for some reason is inaccessible, for example when an attempt is made to open a read-only file for writing.

So you should check if the path is correct and if you have the permission to access it.

Julian
  • 65
  • 2
  • 13
0

In play frame we use location as like:

 "@routes.Assets.at("/images/image.jpg")"
SachinGutte
  • 6,947
  • 5
  • 35
  • 58