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

  • 相关阅读:
    pip 配置国内源
    python + excel工资条自动生成
    Mysql 查看表结构
    win10中Pycharm连接mysql时区错误的解决
    kali linux中mariadb加上密码
    静态链表的基本操作
    静态链表dd
    静态链表
    单链表的基本操作
    单链表
  • 原文地址:https://www.cnblogs.com/kaibindirver/p/15797247.html
Copyright © 2011-2022 走看看