First download the jar package from Com. ostermiller. util CVs at this http://ostermiller.org/utils/download.html address.
Public class csvfileparser {</P> <p> private labeledcsvparser csvparser; // CSV parser. For the header information of the first line, automatically loaded as index keywords </P> <p> private int currlinenum =-1; // number of lines read by the file </P> <p> private string [] currline = NULL; // used to store the data of the current row </P> <p>/* <br/> * constructor, <br/> * Param: in inputstream the information stream to be parsed <br/> * throws ioexception <br/> */</P> <p> protected csvfileparser (inputstream in) throws ioexception {</P> <p> csvparser = new labeledcsvparser (New excelcsvparser (in); <br/> currlinenum = csvparser. getlastlinenumber (); </P> <p>/* <br/> * check whether data exists. <br/> * return ture has a row of data, false no data <br/> */<br/> Public Boolean hasmore () throws ioexception {<br/> currline = csvparser. getline (); <br/> currlinenum = csvparser. getlastlinenumber (); <br/> If (null = currline) <br/> return false; <br/> return true; <br/>}</P> <p>/* <br/> * return data of the current row, data pointed to by the keyword <br/> * Param: string filedname header of the row <br/> * return: String returns the data of the current row, data pointed to by the keyword <br/> */<br/> Public String getbyfieldname (string fieldname) {</P> <p> return csvparser. getvaluebylabel (fieldname ); <br/>}</P> <p>/* <br/> * close the parser <br/> */<br /> Public void close () throws ioexception {<br/> csvparser. close (); </P> <p >}</P> <p>/* <br/> * read data from the current row <br/> * return string [] read data from the current row <br/> */<br/> Public String [] Readline () throws ioexception {<br/> currline = csvparser. getline (); </P> <p> currlinenum = csvparser. getlastlinenumber (); </P> <p> return currline; </P> <p >}</P> <p> Public getcurrlinenum () {</P> <p> return currlinenum; </P> <p >}</P> <p> Public static void main (string [] ARGs) throws exception {</P> <p> // create a resolution information stream <br/> inputstream in = new fileinputstream (new file ("C: perflogsdata_000002.csv ")); </P> <p> // instance parser csvfileparser <br/> csvfileparser parser = new csvfileparser (in ); </P> <p> // read data <br/> while (parser. hasmore () {</P> <p> system. out. print (parser. getbyfieldname ("time") + ""); // time indicates the header data <br/> system. out. print (parser. getbyfieldname ("Total") + ""); <br/> system. out. print (parser. getbyfieldname ("DPC time") + ""); <br/> system. out. print (parser. getbyfieldname ("interrupt time") + ""); <br/> system. out. print (parser. getbyfieldname ("processor time") + ""); </P> <p >}</P> <p> parser. close (); </P> <p >}< br/>