zoukankan      html  css  js  c++  java
  • java 读取本地json文件

    参考 https://www.cnblogs.com/wkfvawl/p/11876107.html 

    maven依赖

     <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>fastjson</artifactId>
            <version>1.2.47</version>
     </dependency>
    

      

    读取json的方法

    //读取json文件
        public String readJsonFile(String Filename #传文件的路径) {
            String jsonStr = "";
            try {
                File jsonFile = new File(Filename);
                FileReader fileReader = new FileReader(jsonFile);
                Reader 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();
    //            System.out.println(jsonStr.getClass().getName());
                return jsonStr;
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
    

    获取项目文件相对路径的方法见: https://www.cnblogs.com/kaibindirver/p/15797181.html

  • 相关阅读:
    异常处理
    弹出对话框
    ef——存储过程
    事务
    linq——常用方法
    Linq
    asp get与post获取的区别
    Web服务的调用
    AJAX控件——多层弹出Accordion
    数据绑定
  • 原文地址:https://www.cnblogs.com/kaibindirver/p/15797247.html
Copyright © 2011-2022 走看看