Hi I have a web Application which uses servlets. As soon as any user Logs i create a folder for the user and the files uploaded by the user are stored in that folder. Now when the users Logs out of the Application I am supposed to delete the folder and all its content.
I used File API to achieve this But I get a
[Inline]
java.security.AccessControlException: access denied (java.io.FilePermission C:\Sun\ApplicationServer\nodeagents\SPINE-POD03\AppServer1\applications\j2ee-apps\harness\simulator_war\temp\guest1\input\ACFHasResourcePermissionsRequest.xml delete)
[/inline]
I use SJAS 8.1 as my application server the code is as follows
protected void doGet(
HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession();
File userDir = new File((String)session.getAttribute(WEB_USER_FOLDER));
recursivelyDeleteDirectory(userDir);
session.invalidate();
System.out.println("Session Destroyed ");
response.sendRedirect(WEB_LOGIN_URL);
}
private void recursivelyDeleteDirectory(File dir) throws IOException {
if ((dir == null) || !dir.isDirectory()) throw new IllegalArgumentException(dir + " not a directory");
final File[] files = dir.listFiles();
final int size = files.length;
System.out.println("Files size = " + size);
for (int i = 0; i < size; i++) {
if(files[i].isDirectory()) {
recursivelyDeleteDirectory(files[i]);
} else files[i].delete();
}
dir.delete();
}
Please can any one help me out with this issue..
Thanks in Advance