问题
- spring boot 打包后如何获取jar包的位置
- spring boot 获取resources文件夹下面的文件
解答
1.jar包位置
ApplicationHome applicationHome = new ApplicationHome(this.getClass());
java.io.File file = applicationHome.getDir();
String route = file.getAbsolutePath();
2.获取resources文件下的文件
InputStream fd = ClassUtils.getDefaultClassLoader().getResourceAsStream("resources下文件路径");
BufferedReader br = new BufferedReader(new InputStreamReader(fd));
StringBuffer sb = new StringBuffer();
String readLine;
while ((readLine = br.readLine()) != null) {
if (readLine.charAt(0) == '-') {
continue;
} else {
sb.append(readLine + "
");
}
}