如何在java中获取浏览的文件路径 [英] How to get browsed file path in java

查看:39
本文介绍了如何在java中获取浏览的文件路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得一个浏览过的文件路径.我试过喜欢

I want to get a browsed files path. i tried like it

Object objUploadEvent = ctx.getTriggerEvent();
        if (objUploadEvent != null && (objUploadEvent instanceof UploadEvent)) {
            upEvent = (UploadEvent) objUploadEvent;
        }
        if (upEvent != null) {
            Media media = upEvent.getMedia();
            File file=new File(media.getName());
            this.path = file.getAbsolutePath();
        }

但是 getAbsolutePath 给出了来自 eclipse 的路径.说如果我的文件在 c://doc/abc 中,那么它应该给出路径为 c://doc/abc/myfile.txt

But getAbsolutePath is giving path from eclipse. say if my file is in c://doc/abc then it should give path as c://doc/abc/myfile.txt

谢谢

推荐答案

如果我理解正确,您想要源文件在客户端上的位置,而不是文件在客户端上的位置服务器?

If I understand correctly, you want the location of the source file on the client as opposed to the location of the file on the server?

出于安全原因,这是不可能的,抱歉.

This is not possible for security reasons, sorry.

您会在 StackOverflow 和其他地方找到大量关于此的讨论(有时参考 某些浏览器实施此安全功能的假路径"症状.

You'll find plenty of discussion about this on StackOverflow and elsewhere (sometimes in reference to the 'fakepath' symptom of some browser's implementation of this security feature.

无需过多赘述,此安全功能的原因很简单;任何网站都不需要(阅读:能够)找出有关用户文件系统的任何信息.因此,当文件上传到服务器时,只应发送文件数据.

Without going into too much detail, the reasoning for this security feature is quite simple; no website should need to (read: be able to) find out anything about a user's file system. As such, when a file is uploaded to a server only the file data should be sent.

从技术上讲,这在一些较旧的浏览器中是可能的(例如:我相信 IE6),但在这一点上它是一个非常普遍的安全功能,你会很不幸地依赖这些信息.

Technically, it was possible in some older browsers (eg: IE6 I believe) but is a pretty ubiquitous security feature at this point and you would be ill fated to depend on this information.

这篇关于如何在java中获取浏览的文件路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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