Del format is similar to CSV, my test file here Test.del is a set of data from the DB2 database.
The MAVEN coordinates of the Apache Commons CSV are:
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-csv --><dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-csv</artifactId> <version>1.5</version></dependency>
Test procedure:
Package test;import Java.io.File;import Java.io.FileInputStream;import java.io.IOException;import Java.io.InputStream;import Java.io.InputStreamReader;import Java.io.Reader;import java.util.ArrayList;import java.util.List;import Org.apache.commons.csv.CSVFormat;import Org.apache.commons.csv.CSVParser;import Org.apache.commons.csv.CSVRecord; Public classDelfileparser { Public Staticlist< list<string> >Parsefile(File file) {List reslist =Newarraylist< list<string> > ();Try{InputStream is =NewFileInputStream (file); InputStreamReader reader =NewInputStreamReader (IS,"GB2312"); Csvparser parser =New Csvparser(Reader, Csvformat.)DEFAULT); for(Csvrecord Record:parser) {List<string> tmplist =NewArraylist<string> (); for(String S:record) {if(s! =NULL) s = S.Trim(); Tmplist.Add(s); } reslist.Add(tmplist); } is.Close(); Reader.Close();returnReslist; }Catch(IOException e) {e.Printstacktrace();return NULL; } } Public Static void Main(string[] args) {list< list<string> > reslist =Parsefile(NewFile ("D:\\Test.del "));//Test for(list<string> tmplist:reslist) { for(String s:tmplist) {System. out.Print(S +","); } System. out.println(); } }}
Using the default format does not use the first row as the header.
For more information see: http://commons.apache.org/proper/commons-csv/user-guide.html
Parsing del (CSV-like) format files using Apache Commons CSV