Found some tutorials earlier on this too, using JSP. Tweaked their code a bit and it works in my machine (Resin 2.1 + J2SDK1.4.0).
But when uploaded into my hosting server to be tested, this exception pops up: java.security.AccessControlException: access denied (java.io.FilePermission /tut/z.png delete) at java.security.AccessControlContext.checkPermission(AccessControlContext.java:264) at java.security.AccessController.checkPermission(AccessController.java:427) at java.lang.SecurityManager.checkPermission(SecurityManager.java:532) at java.lang.SecurityManager.checkDelete(SecurityManager.java:990) at java.io.File.delete(File.java:869) at javax.imageio.ImageIO.write(ImageIO.java:1482) at _pngwrite__jsp._jspService(/tut/pngwrite.jsp:19) at com.caucho.jsp.JavaPage.service(JavaPage.java:75) at com.caucho.jsp.Page.subservice(Page.java:506) at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182) at com.caucho.server.http.Invocation.service(Invocation.java:315) at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135) at com.caucho.server.http.RunnerRequest.handleRequest(RunnerRequest.java:346) at com.caucho.server.http.RunnerRequest.handleConnection(RunnerRequest.java:274) at com.caucho.server.TcpConnection.run(TcpConnection.java:139) at java.lang.Thread.run(Thread.java:595)
While waiting for the hosting to get back to me on this issue, I was wondering if this is caused by the restriction imposed by the hosting, or should I tweak my code a bit more to fix it ?
In a hosted environment you won't have access to the complete file system, just to your personal space or web app directory. That most likely does not include a top-level directory called "/tut". You'll need to save the image in a directory that's part of your environment there.
Don't count your weasels before they've popped. And now for a mulberry bush related tiny ad: