JSP – Checking if a file exists. Posted in : Java筆記 2018-01-04 這個 sample code 滿簡單的: ServletContext app = getServletContext(); String path = app.getRealPath("/"); File theFile = new File(path + "/images/your-file.jpg"); out.print("File Exists: " + theFile.exists() + "<br/>"); Java