夢幻之旅

          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
          主站蜘蛛池模板: 都昌县| 固原市| 墨脱县| 安国市| 体育| 南澳县| 淳化县| 法库县| 岳阳县| 马龙县| 佛学| 巍山| 易门县| 峨眉山市| 恭城| 赞皇县| 廊坊市| 台东县| 乌恰县| 油尖旺区| 丹巴县| 伊川县| 德惠市| 精河县| 望谟县| 东台市| 玉溪市| 明水县| 高邑县| 濮阳县| 额敏县| 玉山县| 中西区| 舒兰市| 凭祥市| 申扎县| 游戏| 沙河市| 邢台市| 浦城县| 高青县|