public Result readProperties(MultipartFile file){
String fileSuffix = ".properties";
String suffix = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
if(!fileSuffix.equals(suffix)){
return ResponseUtils.fail(ResultCode.FAIL,null,"请输入.properties格式文件");
}
Properties prop = new Properties();
List<ConfigVO> configVOS = new ArrayList<>();
try {
//读取属性文件
FileInputStream fis= (FileInputStream) file.getInputStream();
InputStream bis=new BufferedInputStream(fis);
BufferedReader bf = new BufferedReader(new InputStreamReader(bis));
//加载属性列表
prop.load(bf);
Iterator<String> it=prop.stringPropertyNames().iterator();
while(it.hasNext()){
ConfigVO configVO = new ConfigVO();
String key=it.next();
configVO.setConfigName(key);
String value = prop.getProperty(key);
if(value.contains(
"#")){
configVO.setValue(value.substring(0, value.indexOf("#")-1));
configVO.setDescription(value.substring(value.indexOf(
"#")+
1,value.length())); }
else { configVO.setValue(value.substring(
0,value.length())); } configVOS.add(ConfigVO); }
//关闭的时候只需要关闭最外层的流就行了 bf.close(); bis.close(); }
catch (Exception e) { e.printStackTrace(); }
return ResponseUtils.success(ResultCode.SUCCESS,configVOS,"返回成功!");
}