Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Servlet相对路径“;“未找到路径”;_Java - Fatal编程技术网

Java Servlet相对路径“;“未找到路径”;

Java Servlet相对路径“;“未找到路径”;,java,Java,我正在尝试将文件保存到我的文件夹“ProfileImages”,该文件夹位于WebContent中/ 当我以下面的路径运行时,我得到的文件未找到异常 String appPath = request.getServletContext().getRealPath("/"); String savePath = appPath + "WebContent" + File.separator + "ProfileImages"; System.out.println(appPath + "Web

我正在尝试将文件保存到我的文件夹“ProfileImages”,该文件夹位于WebContent中/

当我以下面的路径运行时,我得到的文件未找到异常

String appPath = request.getServletContext().getRealPath("/");

String savePath = appPath + "WebContent" + File.separator + "ProfileImages";

System.out.println(appPath + "WebContent" + File.separator + "ProfileImages");
印刷品提供:

C:\Users\me\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\Test\WebContent\ProfileImages\image.jpg (path not found)
无需将“WebContent”文件夹放入保存路径,因为将“/”传递给getRealPath()将返回项目扩展WAR文件的/web文件夹的绝对磁盘文件系统路径

String savePath = appPath +  File.separator + "ProfileImages";
另见


谢谢,我将在测试时坚持使用绝对路径。但当我把它作为战争部署时,它起了作用。