转自:http://www.cnblogs.com/pricks/archive/2009/11/11/1601044.html import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class test { public static void main(String[] args)
很多时候,我们都将配置文件放在eclipse的src目录下,这个位置,相当于,当导出可执行jar包后,配置文件放在和jar同级的目录中,比如jar包放在/opt目录下,则配置文件放在/opt下,则jar包就可以读取配置文件中的内容.此时,java代码中可以通过 String path=CommonOperation.class.getResource("/").getPath(); FileInputStream fin = new FileInputStream(path+"
之前学习的时候遇到的一个问题 org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sqlSessionFactory' defined in class path resource [com/jevin98/demo/config/dao/SessionFactoryConfiguration.class]: Invocation of init method failed
随手写了一个java小工具,maven打包成功后,发现工具总是读不到打在jar包中的文件信息,要读取的文件位于 /src/main/resources 目录下,打包成功后,文件就在jar包中根目录下,一直以为是路径错误,之后用this.getClass().getClassLoader().getResource("").getPath();发现路径是xxx.jar!/com/demo/..形式,路径总是获取不对. 之后试了一下BufferedReader in = new Buffe