Reputation: 6328
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?
Upvotes: 4
Views: 5863
Reputation: 1108722
Commons IO offers FilenameUtils#getName()
for the exact purpose.
String filename = FilenameUtils.getName(event.getFile().getFileName());
Upvotes: 10