gpt4 book ai didi

java - 如何访问 webapp 中我的应用程序附近的文件夹?

转载 作者:行者123 更新时间:2023-12-01 13:53:08 24 4
gpt4 key购买 nike

我的应用程序位于 wtpwebapps 文件夹下

wtpwebapps->myapp

我的文件位于 wtpwebapps->files 文件夹下

wtpwebapps->files->file1
wtpwebapps->files->file2
wtpwebapps->files->file3

我已经尝试过

request.getSession().getServletContext().getRealPath();

并得到了这条路径

workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps

当我追加时

"\files\file1"

到路径并访问该文件,然后它给我错误

The requested resource is not available

如何解决这个问题?

最佳答案

试试这个:

File currentDir=new File(request.getSession().getServletContext().getRealPath())
// or try this instead too:
// File currentDir=new File(".");

File myFile=new File(currentDir,"files\\file1");

关于java - 如何访问 webapp 中我的应用程序附近的文件夹?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19806400/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com