zoukankan      html  css  js  c++  java
  • CSV文件读取

     

    public class Goods {
        private String name;
        private int type;
        private Double price;
        
        public Goods(){
            
        }
        
        public Goods(String name, int type, Double price) {
            super();
            this.name = name;
            this.type = type;
            this.price = price;
        }
    
        public String getName() {
            return name;
        }
        public void setName(String name) {
            this.name = name;
        }
        public int getType() {
            return type;
        }
        public void setType(int type) {
            this.type = type;
        }
        public Double getPrice() {
            return price;
        }
        public void setPrice(Double price) {
            this.price = price;
        }
        
    }
    public class Demo {
    
        public static void fun() {
            String path = "csv/4399.csv";
            List<Goods>list = new  ArrayList<Goods>();
            try {
                CsvReader reader = new CsvReader(path, '	',
                        Charset.forName("UTF-16LE"));
                reader.readHeaders();// 跳过表头 如果需要表头的话,不要写这句。
                reader.readHeaders();
                reader.readHeaders();
                int name_pos = 0; //商品名称位置
                int type_pos = 1; //商品类型位置
                int price_pos = 2; //商品价格位置
                
                while (reader.readRecord()) { // 逐行读入除表头的数据
                    Goods goods = new Goods();
                    goods.setName(reader.get(name_pos));
                    goods.setType(Integer.parseInt(reader.get(type_pos)));
                    goods.setPrice(Double.parseDouble(reader.get(price_pos)));
                    list.add(goods);
                }
                reader.close();
    
            } catch (IOException e) {
                e.printStackTrace();
            }
    
            
            for (Goods goods : list) {
                System.out.println(goods.getName());
                System.out.println(goods.getType());
                System.out.println(goods.getPrice());
            }
        }
        public static void main(String[] args) {
            fun();
        }
    }
  • 相关阅读:
    使用zoom.js 给博客园的图片添加点击图片放大功能
    html上传多图并预览
    html页面选择图片上传时实现图片预览功能
    html实现点击图片放大功能
    layui常用功能
    七牛云上传与删除图片
    寻找七牛云存储配置参数
    TP5之发送邮件
    TP5之一次选择多张图片并预览
    TP5之页面跳转样式
  • 原文地址:https://www.cnblogs.com/sflik/p/4847488.html
Copyright © 2011-2022 走看看