[英]How can I find the path of a user-defined configure file (xml) in a web project of Java
I add a file under "webapp",but how can I access it? 我在“ webapp”下添加了文件,但如何访问? The server is tomcat and Spring framework as framework.
服务器是以tomcat和Spring框架为框架。
Thanks in advance. 提前致谢。
Here is some code and output: 这是一些代码和输出:
System.out.println("dddddddddddddddddddddddddddd");
//System.out.println(path.getPath());
InputStream is = getClass().getResourceAsStream("/WEB-INF/GroupWebService.xml");
if (null == is ){
System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeee");
}
And the output is 输出是
log4j:WARN Please initialize the log4j system properly.
dddddddddddddddddddddddddddd
eeeeeeeeeeeeeeeeeeeeeeeeeeee
Mar 15, 2012 1:55:52 PM org.apache.catalina.core.ApplicationContext log
INFO: Initializing Spring FrameworkServlet 'application'
You can use 您可以使用
File directory = new File (".");
String path = "";
try {
path = directory.getAbsolutePath()
System.out.println ("Current directory's absolute path: "+ directory.getAbsolutePath());
}catch(Exception e) {
System.out.println("Exceptione is ="+e.getMessage());
}
Which will probably print path of your project directory and then you can use following statement to traverse to your WEB-INF 这可能会打印项目目录的路径,然后可以使用以下语句遍历到WEB-INF
if(!path.equals("")){
path += File.seperator + "WEB-INF" + File.seperator + "filename.xml";
}
System.out.println("dddddddddddddddddddddddddddd");
//System.out.println(path.getPath());
InputStream is = getClass().getResourceAsStream("/WEB-INF/util.tld");
if (null == is ){
System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeee");
}else
{
System.out.println(is.getClass().getName());
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.