关于JAVA 获取src目录包文件下的文件 路径问题

public static void main(String[] args) {
InputStream in = null;
File file = new File("com/teamax/geocoding/config/geocoding.properties");
String filePath = file.getAbsolutePath();
System.out.println(filePath);

String url = Thread.currentThread().getContextClassLoader().getResource("com/teamax/geocoding/config/geocoding.properties").getPath().substring(1);
System.out.println(url);

URL url2 = ClassLoader.getSystemResource("com/teamax/geocoding/config/geocoding.properties");
System.out.println(url2.toString());

String str = System.getProperty("com/teamax/geocoding/config/geocoding.properties");
System.out.println(str);

in = test.class.getResourceAsStream("../config/geocoding.properties");
System.out.println(in.toString());

ClassLoader cl = Thread.currentThread().getContextClassLoader();
InputStream stream = cl.getResourceAsStream("com/teamax/geocoding/config/geocoding.properties");
System.out.println(stream.toString());

test t = new test();
t.test();

}

public void test(){
File file2=new File(this.getClass().getResource("/").getPath().substring(1)+"com/teamax/geocoding/config/geocoding.xml");
String xmlPath = file2.getAbsolutePath();
System.out.println(xmlPath);
}

 

 

你可能感兴趣的:(java)