我在“webapp”下添加了一个文件,但如何访问它? 服务器端采用tomcat和Spring框架作为框架。
提前致谢。
这是一些代码和输出:
System.out.println("dddddddddddddddddddddddddddd");
//System.out.println(path.getPath());
InputStream is = getClass().getResourceAsStream("/WEB-INF/GroupWebService.xml");
if (null == is ){
System.out.println("eeeeeeeeeeeeeeeeeeeeeeeeeeee");
}
输出是
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'
最佳答案
你可以使用
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());
}
这可能会打印你的项目目录的路径,然后你可以使用以下语句遍历到你的WEB-INF
if(!path.equals("")){
path += File.seperator + "WEB-INF" + File.seperator + "filename.xml";
}
关于java - 如何在Java的Web项目中找到用户定义的配置文件(xml)的路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9714491/