读取resources下文件的方法 网上有问答如下:问: new FileInputStream("src/main/resources/all.properties") new FileInputStream("./src/main/resources/all.properties") 上面两个无法读取maven下资源文件目录下的文件嘛,总是提示找不到该路径,这么写错了嘛,但是我的其他maven可以读取 答: 要取编译后的路径,而不是你看到的src/main/re
之前学习的时候遇到的一个问题 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
maven工程打jar包,部署到服务器上以后,获取resource下文件的绝对路径是找不到该文件的 只能用流的方式获取,代码如下: import lombok.extern.slf4j.Slf4j; import java.io.*; import java.util.ArrayList; import java.util.List; /** * Created by dell on 2019/05/26. */ @Slf4j public class FileTxtHandleUtil { p
读取jar包内配置文件: Properties config = new Properties(); InputStream in = this.getClass().getClassLoader().getResourceAsStream("/configfilename.properties"); InputStream in =Thread.currentThread().getContextClassLoader().getResource("/configfilen
随手写了一个java小工具,maven打包成功后,发现工具总是读不到打在jar包中的文件信息,要读取的文件位于 /src/main/resources 目录下,打包成功后,文件就在jar包中根目录下,一直以为是路径错误,之后用this.getClass().getClassLoader().getResource("").getPath();发现路径是xxx.jar!/com/demo/..形式,路径总是获取不对. 之后试了一下BufferedReader in = new Buffe