InputStream in = TestPath.class.getClassLoader().getResourceAsStream("test.txt");
String pa= TestPath.class.getClassLoader().getResource("").getPath(); ///E:/renpm/workspace/TestCode/web/WEB-INF/classes/ String pa2 = TestPath.class.getResource("").getPath(); ///E:/renpm/workspace/TestCode/web/WEB-INF/classes/com/sensky/all/test2/controller/path/
比如上面的三句话,TestPath是一个类,同过这个类能够获得到classloader,也同时能够获得classloader的路径,在加载文件的时候只要使用getResourceAsStream("test.txt");把与classloader在一个文件路径下的文件转化成输入流。这个输入流也是二进制的,也就是说只是利用classloader把文件以流的方式导入,而不是真正意义上的使用classloader来进行加载!!!
String pa= TestPath.class.getClassLoader().getResource("").getPath(); ///E:/renpm/workspace/TestCode/web/WEB-INF/classes/ String pa2 = TestPath.class.getResource("").getPath(); ///E:/renpm/workspace/TestCode/web/WEB-INF/classes/com/sensky/all/test2/controller/path/
比如上面的三句话,TestPath是一个类,同过这个类能够获得到classloader,也同时能够获得classloader的路径,在加载文件的时候只要使用getResourceAsStream("test.txt");把与classloader在一个文件路径下的文件转化成输入流。这个输入流也是二进制的,也就是说只是利用classloader把文件以流的方式导入,而不是真正意义上的使用classloader来进行加载!!!
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货