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

        public void import5(){
            //解析xlsx文件
            String path="E:\bbox_list.xlsx";
            Map<String, List<List<String>>> columnMap = null;
            try {
                Workbook  wb = new XSSFWorkbook(new FileInputStream(new File(path)));
                Sheet  st = wb.getSheetAt(0);
                if(st != null){
                    columnMap = new HashMap<String, List<List<String>>>(st.getLastRowNum());//定义columnMap,存放图及它的分类和框
                    System.out.println(st.getLastRowNum());        
                    System.out.println("--------------st.getLastRowNum()-------------");    
                    for(int i=0;i<=st.getLastRowNum();i++){
                        Row row = st.getRow(i);
                        List<List<String>> informationLists = new ArrayList<List<String>>();//定义大list
                        List<String> informationList = new ArrayList<String>();             //定义小list
                        if(row != null){
                            int rows = row.getLastCellNum();//每行有6列                
                            if(rows>0){                            
                                for(int j=0;j<rows;j++){
                                    Cell cell = row.getCell(j);
                                    informationList.add(cell.toString());//内层小list取到每一列的值                                        
                                }
                                if(columnMap.containsKey(informationList.get(0))){//存进columnMap中;如果columnMap已经存在该图,在它的信息上追加新list                                    
                                    List<List<String>> value = columnMap.get(informationList.get(0));
                                    value.add(informationList);                        
                                    columnMap.put(informationList.get(0), value);
                                }else{                                            //存进columnMap中
                                    informationLists.add(informationList);
                                    columnMap.put(informationList.get(0), informationLists);
                                }                            
                                }
                            }
                        }
                    }
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                System.out.println("文件未找到.." + e.getClass().getName() + "	 信息:" + e.getMessage());
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                System.out.println("Io异常:" + e.getClass().getName() + "	 信息:" + e.getMessage());
                e.printStackTrace();
            }
            System.out.println(columnMap);        
    
            //上传图像并分类并带框
            //取到文件夹下分类的所有图片路径,并取到图片的MD5----------------------
             FolderUtil fu=new FolderUtil();        
             List<String> imgList=fu.refreshFileList("D:\a", "jpg");
             int countadd=0;
             //Map<String,String> jpgnamelist = new HashMap<String,String>();//名字已存在,或者MD5已存在(不明显),读取原名字图片地址,不上传新的
             for(String imgUrl:imgList){
                 String jpgname = (imgUrl.split("\\")[2]);//.split("\.")[0];//取到图片名字
                 System.out.println(jpgname);              //打印图片名字
                 //取到图片的MD5 
                 File imgFile = new File(imgUrl);    
                 //生成缩略图
                 InputStream in = null;
                 try {
                     in = new FileInputStream(imgFile);
                     String fileMd5Name=UploadFile.getFileMD5(in);
                     if(in!=null)
                          in.close();                 
                     //上传原图                
                      String opath=this.upFile(imgUrl, "jpg");
                     //缩略图
                     File simgFile=new File(imgUrl);
                     Map<String,Object> map=ImageZipUtil.zipImageFileByte(simgFile,310, 0, 1f);
                     byte[] bt = (byte[]) map.get("bt");                 
                     ByteArrayInputStream bin = new ByteArrayInputStream(bt);
                     String spath= this.upFile(bin, bt.length, "jpg");
                     System.out.println(columnMap.get(jpgname));                //打印map里图片对应value
                     int listcount=columnMap.get(jpgname).size();                 
                     for(int i=0;i<listcount;i++){
                         List<List<String>> outLists = columnMap.get(jpgname);//定义大list
                         List<String> inList = outLists.get(i);
                         System.out.println(inList);             //打印当前小list
                         String TypeId="";
                         System.out.println(inList.get(1));     //打印分类名
                         JSONObject obj = new JSONObject();
                         obj.put("x", Double.valueOf(inList.get(2)));
                         obj.put("y", Double.valueOf(inList.get(3)));
                         obj.put("width", Double.valueOf(inList.get(4)));
                         obj.put("height",Double.valueOf(inList.get(5)));    
                         JSONArray arrayNew=new JSONArray();
                         arrayNew.add(obj);
                         System.out.println(arrayNew);          //打印json
                         switch (inList.get(1)) {
                            case "Atelectasis":
                                //积液
                                TypeId="64c1282028484899a9e6dcff5c0a71df";
                                System.out.println("Atelectasis-------------------------");
                                break;
                            case "Cardiomegaly":
                                //皮下积气
                                TypeId="254d4860e735438e9525981ccf814277";
                                break;
                            case "Effusion":
                                //气胸
                                TypeId="b11665be08c34045a926671011f1ffd5";
                                break;
                            case "Infiltrate":
                                //陈旧
                                TypeId="b25b7ca9aeb5467d94279d49b24bb441";
                                break;
                            case "Mass":
                                //正常:
                                TypeId="89d1e0832a184c4f92cb233d4cd55a1f";
                                break;
                            case "Nodule":
                                //渗出
                                TypeId="9bb7e278fb3a4f75adf03c7f28f23aa4";
                                break;
                            case "Pneumonia":
                                //渗出
                                TypeId="d5d96332d1c74dddbc79b1ed9b17d9e2";
                                break;
                            case "Pneumothorax":
                                //渗出
                                TypeId="34dd7e4a16de421c8cd1d73f22f19008";
                                break;
                            default:
                                System.out.println(jpgname + " 异常位置: " + inList.get(1));
                                //return null;                     
                     }
                     TagImg  newImg=new TagImg();
                     newImg.setImgMd5(fileMd5Name);
                     newImg.setImgUrl(opath);        
                     newImg.setName(jpgname);    
                     newImg.setImgUrlThumb(spath);
                     newImg.setCreateUser("yl-921");
                     newImg.setOrgId("81dae004980145ffbd261717b49f35b6");
                     newImg.setSetId("e2bf364d87854293a374b49d2609d9c7");    
                     newImg.setTypeId(TypeId);
                     newImg.setTagFlag(1);
                     newImg.setTagJson(arrayNew.toString());        
                     //newImg.setTagJson(tagJson);
                     countadd++;
                     System.out.println(countadd);
                     tagImgService.save(newImg);   
                        }                 
                     
                     bin.close();
                     bt=null;
                     
                } catch (Exception e) {
                    // TODO: handle exception
                }
              }
             System.out.println("共: "+imgList.size()+" 本次添加:"+countadd);
        }
  • 相关阅读:
    bzoj 5092: [Lydsy1711月赛]分割序列
    bzoj1173: [Balkan2007]Point
    bzoj1536: [POI2005]Akc- Special Forces Manoeuvres
    bzoj2178: 圆的面积并
    bzoj1043 下落的圆盘
    bzoj2674 Attack
    bzoj1201: [HNOI2005]数三角形
    bzoj3135: [Baltic2013]pipesd
    bzoj1760 [Baltic2009]Triangulation
    bzoj3136
  • 原文地址:https://www.cnblogs.com/lely/p/10364587.html
Copyright © 2011-2022 走看看