Im using java and jsf and I would like to create a folder within the server and then temporary save the files and delete it afterwards(not the folder itself).
I’ve tried this code:
boolean folderPath;
folderPath = new File ("/Images").mkdir();
but the code above created the folder in my local disk.
Don’t do that. You can never guarantee that the WAR folder is writable or even on physical disk. For example, when the servletcontainer is configured to expand the WAR into memory instead of into disk.
As it’s apparently a temporary file, rather just use
File#createTempFile():Or use an external folder on the fixed disk file system whose absolute path is to be set as VM argument or some configuration setting.
Update: you could use a servlet to display that file. I gather that it’s an image file. You can use
<h:graphicImage>wherein you set the temp file’s filename in the path.E.g. inside the bean:
and then in the view:
The servlet which should listen on
/images/*can then just look like as follows (exceptional checks are omitted for your exercise):