event.getFile().getFileName() is returning filename with complete path in JSF2.0 with PrimeFaces 3.5
jsf, primefaces, windows
Solution
Commons IO offers `FilenameUtils#getName()` for the exact purpose.
String filename = FilenameUtils.getName(event.getFile().getFileName());
See also:
- Commons FileUpload FAQ on the subject
- How to save uploaded file in JSF
Problem
I am using PrimeFaces v3.5 to upload the files in my windows machine using Firefox browser. `event.getFile().getFileName()` is returning filename with complete path which is causing problems further. Internally PrimeFaces is using Apache commons. I checked the javadoc also but not helping me anymore. To overcome with this issue, I modified the program a little bit like following manner- ``` String fileName = event.getFile().getFileName(); fileName = fileName.substring(fileName.lastIndexOf("\\")); ``` But it's not robust and reliable. Any suggestions please?