JSP: How to check to see if file exists?

Discussion in 'Java' started by Sugapablo, Mar 27, 2006.

  1. Sugapablo

    Sugapablo Guest

    What's the simplest way to see if a file exists on the server in JSP?

    If possible, I'd like the the equivalent of:

    <%
    if(FunctionThatTellsMeFileExists("images/001.png")) {
    out.println("YES");
    }
    else {
    out.println("NO");
    }
    %>


    --
    Sugapablo
    http://www.sugapablo.net
     
    Sugapablo, Mar 27, 2006
    #1
    1. Advertising

  2. Sugapablo

    Carl Guest

    Sugapablo wrote:
    > What's the simplest way to see if a file exists on the server in JSP?
    >
    > If possible, I'd like the the equivalent of:
    >
    > <%
    > if(FunctionThatTellsMeFileExists("images/001.png")) {
    > out.println("YES");
    > }
    > else {
    > out.println("NO");
    > }
    > %>
    >
    >
    > --
    > Sugapablo
    > http://www.sugapablo.net


    You might want to try:
    if ( new java.io.File("C:\test.txt").exists() ) ...

    See also:
    http://java.sun.com/j2se/1.5.0/docs/api/java/io/File.html

    Hope that helps,
    Carl.
     
    Carl, Mar 27, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Pgar
    Replies:
    1
    Views:
    4,988
    =?Utf-8?B?U2FudGhhbmEgR29wYWxhbg==?=
    Nov 15, 2004
  2. Totan
    Replies:
    0
    Views:
    1,075
    Totan
    Apr 17, 2006
  3. Jason Stacy
    Replies:
    2
    Views:
    4,849
    Roedy Green
    Apr 27, 2008
  4. Ulf Meinhardt
    Replies:
    8
    Views:
    6,302
  5. Colin Steadman

    How do I check to see if Oracle SID Exists?

    Colin Steadman, Dec 17, 2003, in forum: ASP General
    Replies:
    2
    Views:
    233
    Colin Steadman
    Dec 18, 2003
Loading...

Share This Page