首页 > Web开发 > 详细

读取json文件参数

时间:2020-01-07 19:32:26      阅读:109      评论:0      收藏:0      [点我收藏+]
package utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
@Slf4j
public class FIleUtil {

    public static String readCsv(String filePath) {
        StringBuilder sb = new StringBuilder();

        try {
            FileReader fr = new FileReader(filePath);
            BufferedReader bf = new BufferedReader(fr);

            String line = "";
            //组装读取结果
            while ((line = bf.readLine()) != null) {
                sb.append(line + "\n");
            }
        } catch (FileNotFoundException e) {
            log.error(e.getMessage(),e.fillInStackTrace());
        } catch (IOException e) {
            log.error(e.getMessage(),e.fillInStackTrace());
        }
        return sb.toString();
    }

    public static void main(String[] args) throws IOException {
        String str = readCsv("data/param.json");
        JSONObject json = JSON.parseObject(str);
        System.out.println(json.getString("name"));
    }
}

读取json文件参数

原文:https://www.cnblogs.com/yjh1995/p/12163056.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!