Convert an UploadedFile into a File
I'm using PrimeFaces 3.2 and I should store a file on filesystem. Now, I know that the class FileUploaded creates a temp file so I would convert it into a real file using java.io.File. Here it is my code: String fileName = "D:/upload/file.zip"; //--- this is an example, in my real code it is dynamic UploadedFile uploadedFile; //--- getters and setters InputStream in = uploadedFile.getInputStream(); OutputStream out = new FileOutputStream(new File(fileName)); int read = 0; byte[] bytes = new byte[1024]; while ((read = in.read(bytes)) != -1) { out.write(bytes, 0, read); } in.close(); out.flush()