时间:2020-12-23 12:24:22 | 栏目:JAVA代码 | 点击:次
直接就把项目中的方法贴出来吧
/** * 读出城市列表文件 */ 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); }