如何在WebContent文件夹中获取文件的真实路径? [英] How can I get real path for file in my WebContent folder?

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

问题描述

我需要在我的WebContent目录中获取文件的真实路径,以便我使用的框架可以访问该文件。它只需要将String文件作为属性,所以我需要在WebContent目录中获取该文件的真实路径。

I need to get real path for file in my WebContent directory, so that framework that I use can access that file. It only takes String file as attribute, so I need to get the real path to this file in WebContent directory.

我使用Spring Framework,因此应该可以进行解决方案在Spring。

I use Spring Framework, so solution should be possible to make in Spring.

推荐答案

如果你需要在servlet中使用它,那么使用 getServletContext()。getRealPath( / filepathInContext)

If you need this in a servlet then use getServletContext().getRealPath("/filepathInContext")!

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

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