java - Extracting some values from a multi column text file -


lets have text file this:

alaska             30-dec-11                                                   cd  station         icao  iata  synop   lat     long   elev   m  n  v  u   c  ak adak nas padk  adk   70454  51 53n  176 39w    4   x     t          7  ak akhiok           pakh  akk           56 56n  154 11w   14   x                8  ak ambler           pafm  afm          67 06n  157 51w   88   x                7  ak anaktuvuk pass   pakp  akp          68 08n  151 44w  642   x                7 

i interested in saving lines start ak. in addition, need save information arrays, station name instance.

for first line want store "adak nas" stationarray, "51" array, same "53", "n", "176", "39" , "w". want each line starts ak.

i'm quite confused on how go this. current code pertaining follows:

//process text file fileinputstream fstream = new fileinputstream("file.txt"); bufferedreader br = new bufferedreader(new inputstreamreader(fstream)); string strline;  //add lines start "ak" arraylist arraylist list = new arraylist(); while ((strline = br.readline()) != null && strline.startswith("ak")) {     list.add(strline); }  iterator itr; (itr=list.iterator(); itr.hasnext(); ) {     string str = itr.next().tostring();     string [] splitst =str.split("\\t");     string junk1 = "\\t"; 

i pulled iterator part online, , don't know how split there, or how put respective values array. i'd appreciate can offer. thanks!

is sort of you're looking for?

list<string> list = new arraylist<string>(); list<string[]> out = new arraylist<string[]>(); while ((strline = br.readline()) != null && strline.startswith("ak")) {     list.add(strline); } for(string line : list){     string[] linearr = str.split("\\t");  } (itr=list.iterator(); itr.hasnext(); ) {     string delimiter = "\\t";     string [] splitst =str.split(delimiter);     //we don't know how many we're going find,     //so should accumulate data in list.     out.add(splitst); } string[] stationarray = out.toarray(new string[out.size()]); 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -