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

  • 相关阅读:
    linux awk命令详解
    Linux 大页面使用与实现简介(转)
    二层设备与三层设备的区别--总结
    Windows下的cd命令
    linux常用命令
    上班第一天
    linux 内核移植和根文件系统的制作
    Sizeof与Strlen的区别与联系
    嵌入式软件工程师面试题
    SpringBoot简单打包部署(附工程)
  • 原文地址:https://www.cnblogs.com/yanduanduan/p/5412488.html
Copyright © 2011-2022 走看看