相对路径很简单,只要找到根目录即可
以weblogic7为例
通常在启动一个服务后,默认的根目录是域名对应的目录。
例如建立testdomain,此时根目录在bea\user_projects\testdomain目录下此时如果用相对目录读取example.xml,为了方便
可在testdomain目录下建一子目录存放xml文件
例如bea\user_projects\testdomain\example
相对路径则为“/example”
以weblogic7为例
通常在启动一个服务后,默认的根目录是域名对应的目录。
例如建立testdomain,此时根目录在bea\user_projects\testdomain目录下此时如果用相对目录读取example.xml,为了方便
可在testdomain目录下建一子目录存放xml文件
例如bea\user_projects\testdomain\example
相对路径则为“/example”
InputStream is getServletContext().getResourceAsStream( "/WEB-INF/xmlfile.xml" );将xml文件放在/WEB-INF/classes目录下或classpath的jar包中,则:
InputStream is = null;
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
if (classLoader == null) {
classLoader = this.getClass().getClassLoader();
}
is = classLoader.getResourceAsStream(name);这是两种常用的取文件的方法,可以避免硬编码文件路径