美文网首页
读取resources下的文件

读取resources下的文件

作者: Tony_zl | 来源:发表于2020-03-09 23:33 被阅读0次

方法一:

读取文件流

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();

}

相关文章

网友评论

      本文标题:读取resources下的文件

      本文链接:https://www.haomeiwen.com/subject/gvhvdhtx.html