java在Jar包中读取文件
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);
}
}
Loading...