Check if image exists


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Check if image exists

  1. #1
    Join Date
    May 2003
    Posts
    2

    Check if image exists

    Hiya,

    I 'm building a jsp page, and I want to check if an image exists in the folowing structure: "images/image.gif"

    i use the folowing code:

    String fotoString = "images/shopping-cart-image.gif";
    File foto = new File(fotoString);
    if (! foto.isFile()){
    System.out.println("Image doesn't exist");
    fotoString = "images/photo-not-available.gif";
    }

    I have also tried to use foto.exists() in the if clause, but it doesn't work

    can anyone help me, please??
    Robby Bollen
    robbybollen@hotmail.com

  2. #2
    Join Date
    Mar 2003
    Posts
    86

    Context

    When working from a jsp, you root context it the html root of your web app (e.g. /home/myWeb), now when you try to open a file from images/image.gif you ask for the following path

    /home/myWeb/images/image.gif

    Is it there?

    You can always specify a full path.

    Sharbov.

  3. #3
    Join Date
    May 2003
    Posts
    2
    but i can't specify a full path like c:/dir/dir/image.gif...

    when i use request.getContextPath(), i get /fw2/images/image.gif, but to display a img i need to have images/image.gif

    but how can i check if /images/image.gif exists? that's my question
    Robby Bollen
    robbybollen@hotmail.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center