夢幻之旅

          DEBUG - 天道酬勤

             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            671 隨筆 :: 6 文章 :: 256 評論 :: 0 Trackbacks
          package com.framework.commons.util;

          import java.io.FileInputStream;
          import java.io.FileNotFoundException;
          import java.io.IOException;
          import java.io.InputStream;
          import java.util.ArrayList;
          import java.util.List;

          import com.Ostermiller.util.ExcelCSVParser;
          import com.Ostermiller.util.LabeledCSVParser;

          /**
           * <ul>
           * <li>Title:[CsvFileParser]</li>
           * <li>Description: [首先到該http://ostermiller.org/utils/download.html 地址下載com.Ostermiller.util cvs的jar包]</li>
           * <li>Copyright 2009 Upengs Co., Ltd.</li>
           * <li>All right reserved.</li>
           * <li>Created by [Huyvanpull] [2011-7-21]</li>
           * <li>Midified by [modifier] [modified time]</li>
           * </ul>
           * 
          @version 1.0  
           
          */

          public class CsvFileParser
          {
              
          public static String[][] read(String filePath) throws FileNotFoundException, IOException
              
          {
                  
          return read(new FileInputStream(filePath));
              }

              
              
          public static String[][] read(InputStream in) throws IOException
              
          {
                  LabeledCSVParser csvParser 
          = new LabeledCSVParser(new ExcelCSVParser(in));
                  String[][] arr 
          = csvParser.getAllValues();
                  csvParser.close();
                  
          return arr;
              }

              
              
          public static List<ArrayList<String>> read2(String filePath) throws IOException
              
          {
                  
          return read2(new FileInputStream(filePath));
              }

              
              
          public static List<ArrayList<String>> read2(InputStream in) throws IOException
              
          {
                  ArrayList
          <ArrayList<String>> outterLst = new ArrayList<ArrayList<String>>();
                  String[][] outerArr 
          = read(in);
                  
                  ArrayList
          <String> innerLst = null;
                  
          for(String[] innerArr : outerArr)
                  
          {
                      innerLst 
          = new ArrayList<String>();
                      
          for(String s : innerArr)
                      
          {
                          innerLst.add(s);
                      }

                      outterLst.add(innerLst);
                  }

                  
          return outterLst;
              }

              
              
          public static void main(String[] args) throws Exception
              
          {
                  String filePath 
          = "C:/RDS201107180013-Riseedu-110709.csv";
                  ArrayList
          <ArrayList<String>> outterLst = (ArrayList<ArrayList<String>>) CsvFileParser.read2(filePath);
                  
          for (ArrayList<String> inner : outterLst)
                  
          {
                      
          for (String me : inner)
                      
          {
                          System.out.println(me);
                      }

                      System.out.println();
                  }

                  
              }

          }
          posted on 2011-07-21 16:16 HUIKK 閱讀(1210) 評論(0)  編輯  收藏 所屬分類: Java
          主站蜘蛛池模板: 桂东县| 北宁市| 沾化县| 潍坊市| 进贤县| 乐业县| 凉城县| 海口市| 镇坪县| 武城县| 浏阳市| 林芝县| 财经| 通辽市| 建湖县| 黎川县| 余江县| 晋江市| 呼和浩特市| 新竹县| 东海县| 德令哈市| 玉溪市| 黄冈市| 杭州市| 弥勒县| 泰顺县| 淳化县| 巴东县| 青铜峡市| 潢川县| 高雄市| 双鸭山市| 西乌| 盐城市| 郧西县| 泸西县| 鄂托克前旗| 额济纳旗| 东乌| 深水埗区|