/**
* 读取resources下的文件,支持jar
* @param path
*/
public static String readResourcesFile(String path){
try(InputStream bis = FileUtils.class.getClassLoader().getResourceAsStream(path);) {
StringBuffer stringBuffer=new StringBuffer();//用于解析文件
byte[] buff=new byte[1024];
int btr=0;
while ((btr = bis.read(buff)) !=-1){
stringBuffer.append(new String(buff,0,btr,"UTF-8"));
}
return stringBuffer.toString();
}catch(Exception ex) {
LogUtil.error(FileUtil.class,"读取文件失败:",ex);
}
return "";
}
java 读取resources下的文件,支持jar
最新推荐文章于 2024-08-18 21:36:31 发布