[英]how to write java servelt relative file path
i am using SERVLET and i am reading from XML files i want to read the XML files using relative or dynamic paths , i tried the "./directoryName"
and the "fileName"
but non of these worked my path now loooks like this : 我正在使用SERVLET,正在读取XML文件,我想使用相对路径或动态路径读取XML文件,但是尝试了
"./directoryName"
和"fileName"
但这些都不起作用,我的路径现在看起来像这样:
public static final String DEFAULT_INFO_FILES_PATH = "D:/dev/workspace/QwiltSim/src/ps/exalt/qwilt/ui/sim/DevicesInfo.xml";
i want it to be some thing like : 我希望它是这样的:
public static final String DEFAULT_INFO_FILES_PATH = SomeFolderName+"DevicesInfo.xml"
can any one help me please ? 有人可以帮我吗?
ServletContext#getRealPath()
converts relative paths within your application to file system paths. ServletContext#getRealPath()
将应用程序中的相对路径转换为文件系统路径。 If your XMLs are static and you deploy them along with your servlet application, you can store them within the WAR and resolve the path to them using this method. 如果XML是静态的,并且将它们与Servlet应用程序一起部署,则可以将它们存储在WAR中,并使用此方法解析它们的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.