How to get a file’s full path using p:fileUpload
I’m having a problem to get the fullPath of a file which i upload using primefaces component:
<
p:fileUpload fileUploadListener="#{sinavolusturMB.upload}" mode="advanced" dragDropSupport="false" multiple="true" update="messages" sizeLimit="100000" allowTypes="/(\.|\/)(txt)$/" />
public void upload(FileUploadEvent event) throws IOException { file = event.getFile(); String filename = FilenameUtils.getFullPath(file.getFileName()); FacesMessage message = new FacesMessage("Succesful",filename + " is uploaded."); FacesContext.getCurrentInstance().addMessage(null, message); }
File pload işlemine aşağıdaki kodlar eklenirse path sorunu çözülmüş olacaktır :
public void upload(FileUploadEvent event) throws IOException { file = event.getFile(); FacesMessage message = new FacesMessage("Succesful", file.getFileName() + " is uploaded."); FacesContext.getCurrentInstance().addMessage(null, message); String filename = FilenameUtils.getName(file.getFileName()); InputStream input = file.getInputstream(); OutputStream output = new FileOutputStream(new File("C:\\Users\\erman\\Documents\\NetBeansProjects\\OptikFormEE\\OptikFormEE-web\\src\\main\\webapp\\upload\\", filename)); try { IOUtils.copy(input, output); } finally { IOUtils.closeQuietly(input); IOUtils.closeQuietly(output); } }