重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java读取文件内容为string字符串的方法

直接就把项目中的方法贴出来吧

十余年建站经验, 成都网站设计、网站建设客户的见证与正确选择。成都创新互联公司提供完善的营销型网页建站明细报价表。后期开发更加便捷高效,我们致力于追求更美、更快、更规范。

/**
 * 读出城市列表文件
 */
 private String readCityFile() {
  File file02 = new File(path_xinfu, "/cityList.json");
  FileInputStream is = null;
  StringBuilder stringBuilder = null;
  try {
   if (file02.length() != 0) {
    /**
     * 文件有内容才去读文件
     */
    is = new FileInputStream(file02);
    InputStreamReader streamReader = new InputStreamReader(is);
    BufferedReader reader = new BufferedReader(streamReader);
    String line;
    stringBuilder = new StringBuilder();
    while ((line = reader.readLine()) != null) {
     // stringBuilder.append(line);
     stringBuilder.append(line);
    }
    reader.close();
    is.close();
   } else {
    mLoadingLayout.setStatus(LoadingLayout.Empty);
   }

  } catch (Exception e) {
   e.printStackTrace();
  }
  return String.valueOf(stringBuilder);

 }

以上这篇java读取文件内容为string字符串的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持创新互联。


网站栏目:java读取文件内容为string字符串的方法
标题来源:http://cqcxhl.cn/article/gspgcp.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP