This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

ImageIO and .exists can't find file.

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Is there any way to check exactly where in the system it's trying to load the image from?
I am using Iltellij if it matters.


My problem is that when I compile and run the whole thing, even though the file(s) it tries to load does exists, the program can't seem to find it.
 
Saloon Keeper
Posts: 7231
169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you really want to access a file named "filename" (and not the one specified by the filename parameter passed into the method)?
 
Nickalos Klemer
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:Do you really want to access a file named "filename" (and not the one specified by the filename parameter passed into the method)?


Oh, oops.
Even after I fixed "boolean exists = (new File(fileName)).exists();" the problem still persists.
The reason I put that exists thing up anyway was to try to narrow down this problem.
 
Tim Moores
Saloon Keeper
Posts: 7231
169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

ImageIO.read(PDB.class.getResource(fileName))


This looks odd. Why are you using the resource loading mechanism instead of "ImageIO.read(fileName)"? That would cause the file to be searched for at a different location than what the file name specifies.

Also make sure that the account running this code has read access to all (intermediate) directories and files.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic