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?
Commons IO offers FilenameUtils#getName()
for the exact purpose.
String filename = FilenameUtils.getName(event.getFile().getFileName());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With