I am trying to upload an image file to a local folder and getting File Not Found Error. The location pointing out in error message for the upload file is not right. Actually the file location is showing on the error is a combination of my source and destination location. I am trying to upload file to "C:/Users/sam//File/Upload/" from my desktop. Here is the error code,
Error message
java.io.FileNotFoundException: C:\Users\sam\File\Upload\C:\Users\sam\Desktop\test.jpg (The filename, directory name, or volume label syntax is incorrect)
My class file
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.context.FacesContext;
import org.apache.commons.io.IOUtils;
import org.primefaces.event.FileUploadEvent;
@ManagedBean
public class FileUploadView {
private String fileUploadFolder = "C:/Users/sam/File/Upload/";
public void handleFileUpload(FileUploadEvent event) {
FacesMessage message = new FacesMessage("Succesful", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, message);
try {
File targetFolder = new File(fileUploadFolder);
InputStream input = event.getFile().getInputstream();
OutputStream output = new FileOutputStream(new File(targetFolder,
event.getFile().getFileName()));
try {
IOUtils.copy(input, output);
} finally {
IOUtils.closeQuietly(input);
IOUtils.closeQuietly(output);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
and my html
<p:fileUpload fileUploadListener="#{fileUploadView.handleFileUpload}"
mode="advanced" dragDropSupport="false" update="messages"
sizeLimit="100000000" fileLimit="1"
allowTypes="/(\.|\/)(gif|jpe?g|png|xlsx|jpg)$/" />
I also tried example from BalusC, still getting same error, ui with primefaces5.1.