梦幻之旅

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 阅读(1188) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: