import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class text {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String fpath = "D:\\Project\\Text.csv";
File file = new File(fpath);
List lst = null;
try {
lst = read(file, ",", true);
for ( int i = 0 ; i < lst.size(); i++ ) {
System.out.println(lst.get(i));
}
} catch ( Exception e ) {
System.out.println(e);
}
}
/*===============================================================================================
*
* Text 파일을 읽어 List로 리턴한다.
*
* Parameter
* File : Excel 파일
* Delimeter : 필드 구분자
* bDefineTitle : true->첫 번째 Row를 Key로 지정
* false->Cell_x 로 임의의 Key 지정
*
*===============================================================================================
* */
public static List read(File file, String Delimeter, boolean bDefineTitle) throws Exception {
int nInx = 0;
String[] strTmp = null;
List lst = null;
HashMap map = null;
HashMap t_map = null;
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file));
lst = new ArrayList();
t_map = new HashMap();
for( String read = reader.readLine(); read != null; read = reader.readLine() ) {
strTmp = read.split(Delimeter);
if ( nInx == 0) {
for ( int j = 0 ; j < strTmp.length ; j++ ) {
t_map.put(String.valueOf(j), (bDefineTitle)?strTmp[j].trim():"Cell_"+j);
}
} else {
map = new HashMap();
for ( int j = 0 ; j < strTmp.length ; j++ ) {
map.put(t_map.get(String.valueOf(j)), strTmp[j].trim());
}
lst.add(map);
}
nInx++;
}
return lst;
}
}