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

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

问题描述

我使用 PrimeFaces v3.5 使用 Firefox 浏览器将文件上传到我的 Windows 机器中.event.getFile().getFileName() 正在返回带有完整路径的文件名,这进一步导致了问题.PrimeFaces 在内部使用 Apache 公共资源.我检查了 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?

推荐答案

Commons IO 提供 FilenameUtils#getName() 用于确切目的.

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

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

另见:

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