首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

JAVA Appliation上取得资源文件的路径

2012-08-29 
JAVA Appliation下取得资源文件的路径??那么如果得到这个文件呢?先看下面的一个对路径的测试代码import ja

JAVA Appliation下取得资源文件的路径

?


?

那么如果得到这个文件呢?先看下面的一个对路径的测试代码

import java.io.File;public class PathTest {  public static void main(String[] args) throws Exception {    System.out.println(    Thread.currentThread().getContextClassLoader().getResource(""));    System.out.println(PathTest.class.getClassLoader().getResource(""));    System.out.println(ClassLoader.getSystemResource(""));    System.out.println(PathTest.class.getResource(""));    System.out.println(PathTest.class.getResource("/"));    System.out.println(new File("").getAbsolutePath());    System.out.println(System.getProperty("user.dir"));  }}
?

private static Element getRootElement() throws Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document doc = db.parse(ConfigFactoryImplTest. class .getResource("") + "boss-connector-service.xml"); return doc.getDocumentElement(); }?

?



后记:
得到资源文件的路径,在不同的环境(如:Eclipse RCP、Tomcat、Weblogic、简单的Java Application),方法都是略有不同的。具体的环境要具体分析。

热点排行