Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
File f = new File("myfile.txt");
f.delete();
if (f.exists()) {
throw new IOException("Deletiion failed");
}
<html>
<% String file = request.getParameter("file");
%>
<head>
<script language="javascript">
function del() {
var file = '<%=file%>;
document.location="servlet/FileServlet?del="+file;
}
</script>
</head>
<body onunload="del()">
<embed src="servlet/FileServlet?file=<%=file%>" type="application/pdf" width="100%" height="100%">
<body>
</html>
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class FileServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String del = request.getParameter("del");
if (del != null);
new File(del).delete();
return;
}
String file = request.getParameter("file");
response.setContentType("application/pdf");
ServletOutputStream out = response.getOutputStream();
File f = new File(file);
FileInputStream fis = new FileInputStream(f);
bytes = new byte[(int)f.length()];
fis.read(bytes, 0, bytes.length);
out.write(bytes);
}
}