zoukankan      html  css  js  c++  java
  • 文件上传

    CSV文件的上传总结

    1.首选定义上传文件的格式,我这里将文件的格式设置为UTF-8

    2.文件名的取得

    String fileName = file.getOriginalFilename();

    3.文件的路径设定

    String path = "C:/path/";

    4.指定文件夹文件创建

    File filePath= new File(path);

    File file = new File(filePath, File.separator + fileName);

    5.文件不存在,则创建

    if (!file.exists()) {
    file.mkdirs();
    }

    6.CSV文件读取

    String fileUrl = dest.toString();//文件字符串转换

    List<List<String>> records = readCsvFile(file);

    7.

    public List<List<String>> readCsvFile(String file) {

    List<List<String>> readData = new ArrayList<List<String>>();
    BufferedReader reader = null;
    try {
    reader = new BufferedReader(new InputStreamReader(new FileInputStream(file),"UTF-8"));
    String rowData = null;
    while ((rowData= reader.readLine()) != null) {
    if (!"".equals(rowData)) {
    String[] record = rowData.trim().substring(1, rowData.trim().length() - 1).replace(""", "").split(",", -1);
    readData.add(Arrays.asList(record));
    }
    }
    } catch (Exception e) {
    throw new RuntimeException(e);
    } finally {
    try {
    if (reader != null) {
    reader.close();
    }
    } catch (IOException ioe) {
    throw new RuntimeException(ioe);
    }
    }
    return rowData ;
    }

  • 相关阅读:
    noip不知道哪年 货车运输
    bzoj1002轮状病毒
    bzoj1001狼抓兔子
    20171002模拟赛
    20171001模拟赛
    异常
    springmvc-servlet.xml 第二种选择
    springmvc入门
    springmvc-servlet.xml(springmvc-servlet.xml 配置 增强配置)
    777
  • 原文地址:https://www.cnblogs.com/yilizhongzi-yilisha/p/13632922.html
Copyright © 2011-2022 走看看