Hi i am trying to save the uploaded file to a folder in my project but i am not not sure how to give the path. I also want the same name of the uploaded file to be the name of the file stored in the folder.
public void handleFileUpload(FileUploadEvent event) throws IOException {
LOG.info("Entered into save action event");
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
String filename = event.getFile().getFileName();
UploadedFile file = event.getFile();
InputStream input = file.getInputstream();
OutputStream output = new FileOutputStream(new File("src/main/resources/uploads/schema.xsd", filename));
try {
IOUtils.copy(input, output);
} catch (IOException e){
LOG.error("Error in copying file.", e);
}
finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
}