ravi
ravi

Reputation: 6328

event.getFile().getFileName() is returning filename with complete path in JSF2.0 with PrimeFaces 3.5

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

Answers (1)

BalusC
BalusC

Reputation: 1108722

Commons IO offers FilenameUtils#getName() for the exact purpose.

String filename = FilenameUtils.getName(event.getFile().getFileName());

See also:

Upvotes: 10

Related Questions