方法一:
读取文件流
ClassPathResource classPathResource =new ClassPathResource("1.json");
String sql ="";
BufferedReader reader =null;
StringBuilder sbf =new StringBuilder();
try {
File jsonFile = classPathResource.getFile();
reader =new BufferedReader(new FileReader(jsonFile));
String tempStr;
while ((tempStr = reader.readLine()) !=null) {
sbf.append(tempStr);
}
reader.close();
sql = sbf.toString();
}catch (IOException e) {
e.printStackTrace();
}finally {
if (reader !=null) {
try {
reader.close();
}catch (IOException e1) {
e1.printStackTrace();
}
}
}
方法二:
PropertiesLoaderUtils
Properties properties = new Properties();
try {
properties = PropertiesLoaderUtils.loadAllProperties("source.properties");
properties.getProperty("source.url");
properties.getProperty("source.db-version");
properties.getProperty("source.username");
properties.getProperty("source.password").getBytes("iso-8859-1"), "gbk");
} catch (IOException e) {
e.printStackTrace();
}
网友评论