当前位置:编程学习 > JAVA >>

springmvc3.0 读取csv文件进行db更新求助(CSVReader)

测试类:此处的file是我读取到的上传文件

@RequestMapping(value="/csvupload", method = RequestMethod.POST)
    public ModelAndView csvchooseuoload(HttpServletRequest request,
            @RequestParam(value="csvtestfiles", required = false)  CommonsMultipartFile file )throws Exception


本地有一个csv文件用opencsv读取的一个测试版本
File file = new File(filepath);
        FileReader freader = null;
        try{
            /*if(file.isFile()||!file.exists()){
                throw new Exception(filepath+"文件不存在");
        }*/
            //设定文件读取流 
            csvreader  = new CSVReader (new FileReader(file));
            String [] nextLine = null;
            
            while ((nextLine = csvreader.readNext()) != null) {
                System.out.println("所属略称: [" + nextLine[0] + "]\n所属CD: [" + nextLine[1] + "]\n所属名: [" + nextLine[2] + "]\n有効開始日:["+nextLine[3]+"]" +
                 "\n有効終了日:["+nextLine[4]+"]");
                nextLine = csvreader.readNext();
                for(int j= 0;j<nextLine.length;j++){
                    System.out.println(nextLine[j]+"\n");
                }
            }

上传的文件目前无法到csvreader读取,试过很多办法,求高人指点和解决~~~~急赶项目进度。。。
补充:Java ,  Web 开发
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,