zoukankan      html  css  js  c++  java
  • JAVA获取文件数据 ( xxxxx.json )

        //路径fPix
    File filePath = new File(fPix);
    System.out.print("文件路径:" + filePath);
    try {
    if (filePath.isFile() && filePath.exists()) { //判断文件是否存在
    PageData temp = null;
    InputStreamReader read = new InputStreamReader(
    new FileInputStream(filePath), encoding);//考虑到编码格式
    BufferedReader bufferedReader = new BufferedReader(read);
    String lineTxt = null;
    String code = "";
    while ((lineTxt = bufferedReader.readLine()) != null) {
    try {
    String[] linetemp = null;
    lineTxt = lineTxt.trim().replace("uFEFF", "");
    lineTxt = lineTxt.substring(1, lineTxt.length() - 1);
    lineTxt = lineTxt.replaceAll("'", "");
    System.out.println("去除:" + lineTxt);//读取文件内容
    temp = new PageData();
    if (!lineTxt.equals("") && lineTxt.indexOf(", ") != -1) {
    linetemp = lineTxt.split(", ");
    System.out.println(linetemp);
    if (linetemp != null && linetemp.length > 0) {
    for (int j = 0; j < linetemp.length; j++) {
    code = linetemp[j].substring(1, linetemp[j].indexOf(":") - 1).trim();
    System.out.println("code:" + code);
    if (code.equals("code") || code.equals("time")) {
    if (temp != null) {
    temp.put(code, linetemp[j].substring(linetemp[j].indexOf(":") + 2, linetemp[j].length()).trim());
    System.out.println("取出数据:" + temp);
    }
    }
    }
    }
    }
    filelist.add(temp);
    } catch (Exception e) {
    System.out.println("处理本行数据出错:" + lineTxt.toString() + " 错误是:" + e.toString());
    filelist.remove(temp);
    continue;
    }
    }
    read.close();
    } else {
    System.out.println("找不到指定的文件");
    }


    } catch (Exception e) {
    System.out.println("读取文件内容出错");
    e.printStackTrace();
    }
  • 相关阅读:
    乐观锁配置
    @NotBlank注解地正确使用
    Navicat Premium 12.1手动激活
    nacos将服务注册到命名空间
    springcloud中微服务远程调用
    常用的运算符的操作
    时间复杂度和空间复杂度
    前后端分离跨域问题cors
    数据库迁移on_delete 以及NodeNotFoundError问题解决
    python去重后保证顺序不变
  • 原文地址:https://www.cnblogs.com/tutu21ybz/p/6729162.html
Copyright © 2011-2022 走看看