I use the simple File upload of Primefaces in development with Netbeans. My test example is similar to to the Primefaces manual.
My question: where does the file
I used simple mode, GlassFish 4.0 and PrimeFaces 4.0
Backing Bean
private UploadedFile file;
private String destination="C:\\temp\\";
public void upload() {
System.out.println("uploading");
if(file != null) {
System.out.println("the file is" +file);
FacesMessage msg = new FacesMessage("Succesful" + file.getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
try {
copyFile(file.getFileName(), file.getInputstream());
}
catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("uploaf finished");
}
public void copyFile(String fileName, InputStream in) {
try {
// write the inputStream to a FileOutputStream
OutputStream out = new FileOutputStream(new File(destination + fileName));
int read = 0;
byte[] bytes = new byte[1024];
while ((read = in.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
in.close();
out.flush();
out.close();
System.out.println("New file created!");
} catch (IOException e) {
System.out.println(e.getMessage());
}
}
JSF page