package utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import java.io.BufferedReader; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; public class FIleUtil { public static String readCsv(String filePath){ StringBuilder sb=new StringBuilder(); FileReader fr=null; BufferedReader bf=null; try { fr = new FileReader(filePath); bf=new BufferedReader(fr); } catch (FileNotFoundException e) { e.printStackTrace(); } String line=""; try { //组装读取结果 while ((line=bf.readLine())!=null){ sb.append(line+"\n"); } return sb.toString(); } catch (IOException e) { e.printStackTrace(); } finally { if (fr!=null){ try { fr.close(); } catch (IOException e) { e.printStackTrace(); } } if (bf!=null){ try { bf.close(); } catch (IOException e) { e.printStackTrace(); } } } 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文件参数
猜你喜欢
转载自www.cnblogs.com/yjh1995/p/12163056.html
今日推荐
周排行