package com.kuyuntech.vrv.platform.util.core;

import java.io.*;
import java.nio.charset.StandardCharsets;

/**
 * @Description 文件工具类
 * @ClassName FileUtils
 */
public class FileUtils {
    /**
     * 从json文件中读取数据
     *
     * @param jsonFilePath
     * @return
     */
    public static String getDataFromJsonFile(String jsonFilePath) {
        StringBuilder jsonString = new StringBuilder();
        File file = new File(jsonFilePath);

        if (file.exists()) {
            BufferedReader bufferedReader = null;

            try {
                bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(file), StandardCharsets.UTF_8));
                char[] chars = new char[8192];
                int length;
                while ((length = bufferedReader.read(chars)) != -1) {
                    String temp = new String(chars, 0, length);
                    jsonString.append(temp);
                }
            } catch (IOException e) {
                System.out.println("=====获取数据异常=====" + e);
            } finally {
                if (null != bufferedReader) {
                    try {
                        bufferedReader.close();
                    } catch (IOException ex) {
                        System.out.println("=======获取数据时，关闭流异常=======" + ex);
                    }
                }
            }
        }
        return jsonString.toString();
    }
}

