event.getFile().getFileName()返回带有PrimeFaces 3.5的JSF2.0中具有完整路径的文件名 [英] event.getFile().getFileName() is returning filename with complete path in JSF2.0 with PrimeFaces 3.5

查看:134
本文介绍了event.getFile().getFileName()返回带有PrimeFaces 3.5的JSF2.0中具有完整路径的文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PrimeFaces v3.5使用Firefox浏览器将文件上传到Windows计算机中. event.getFile().getFileName()返回具有完整路径的文件名,这进一步导致了问题.内部PrimeFaces使用的是Apache Commons.我检查了 javadoc 也对我没有帮助.

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?

推荐答案

公共IO提供

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

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

另请参见:

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆