package com.manage.util;

import java.io.*;

/**
 * json工具类
 */
public class JsonUtils {

    /**
     * 读取json文件方法
     * @param fileName：json文件存在的本地地址
     * @return
     */
    public static String readJsonFile(String fileName) {
        String jsonStr = "";
        Reader reader=null;
        FileReader fileReader=null;
        try {
            File jsonFile = new File(fileName);
            fileReader = new FileReader(jsonFile);
            reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8");
            int ch = 0;
            StringBuffer sb = new StringBuffer();
            while ((ch = reader.read()) != -1) {
                sb.append((char) ch);
            }
            fileReader.close();
            reader.close();
            jsonStr = sb.toString();
            return jsonStr;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        }finally {
            try {
                reader.close();
                fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
