java在Jar包中读取文件

走着路睡觉
  • java
小于 1 分钟

java在Jar包中读取文件

@SpringBootApplication
public class DemoApplication {

    public static void main(String[] args) throws Exception{
        //this.getClass().getResourceAsStream("/file.txt")
        try (InputStream in = DemoApplication.class.getResourceAsStream("/application.properties");
             BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {

            final String collect = reader.lines().collect(Collectors.joining());
            System.out.println("------------------"+collect);
        }
        //SpringApplication.run(DemoApplication.class, args);
    }

}
上次编辑于:
贡献者: zhaojingbo
Loading...