zoukankan      html  css  js  c++  java
  • 将json文件转换为字符串

    //从给定位置读取Json文件
        public   String readJson(String path){
            //从给定位置获取文件
            File file = new File(path);
            BufferedReader reader = null;
            //返回值,使用StringBuffer
            StringBuffer data = new StringBuffer();
            //
            try {
                reader = new BufferedReader(new FileReader(file));
                //每次读取文件的缓存
                String temp = null;
                while((temp = reader.readLine()) != null){
                    data.append(temp);
                }
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                //关闭文件流
                if (reader != null){
                    try {
                        reader.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return data.toString();
        }

  • 相关阅读:
    请求接口时params和data的区别
    深拷贝
    react学习笔记---父子组件间值得传递
    表单验证自定义二选一
    vue数据复杂时的表单验证
    jq获取路径参数的方法
    删除对象中的元素的方法
    iOS的URL处理
    cocoapod的下载安装解释
    初探博客园
  • 原文地址:https://www.cnblogs.com/yanduanduan/p/5412488.html
Copyright © 2011-2022 走看看