• 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();
    }
  • 相关阅读:
    2015-04
    2014-12
    2014-9
    nginx中ngx_http_ssl_module模块
    nginx中ngx_http_gzip_module模块
    Nginx中ngx_http_log_module模块
    Nginx中ngx_http_auth_basic_moudel和ngx_http_stub_status_module模块
    nginx中ngx_http_access_module模块
    nginx中ngx_http_core_module模块
    Nginx安装
  • 原文地址:https://www.cnblogs.com/tutu21ybz/p/6729162.html
Copyright © 2020-2023  润新知