Saturday, November 22, 2014

see if a file exists in Java

<%@page import="java.io.File"%>
<%
String location = getServletConfig().getServletContext().getRealPath("/") + "x.txt";
File file = new File(location);
if(file.exists() && !file.isDirectory()) {
   %> There is a file. :) <%
} else {
   %> There is NOT a file. :( <%
}
%>

No comments:

Post a Comment