Reading a complicated text file in Java

xpnet

New Member
Lets say I have a text file like this:\[code\]ALASKA 30-DEC-11 CD STATION ICAO IATA SYNOP LAT LONG ELEV M N V U A CAK ADAK NAS PADK ADK 70454 51 53N 176 39W 4 X T 7 USAK AKHIOK PAKH AKK 56 56N 154 11W 14 X 8 USAK AMBLER PAFM AFM 67 06N 157 51W 88 X 7 USAK ANAKTUVUK PASS PAKP AKP 68 08N 151 44W 642 X 7 US\[/code\]I am only interested in saving lines that start with AK. In addition, I need to save certain information into arrays, like my STATION name for instance.For the first line I want to store "ADAK NAS" into a stationArray, "51" into an array, same with "53", "N", "176", "39" and "W". I want to do this for each line that starts with AK.I'm really quite confused on how to go about this. My current code pertaining to this is as follows:\[code\]//process text fileFileInputStream fstream = new FileInputStream("file.txt");DataInputStream in = new DataInputStream(fstream);BufferedReader br = new BufferedReader(new InputStreamReader(in));String strLine;//add lines that start with "AK" to arraylistArrayList list = new ArrayList();while ((strLine = br.readLine()) != null && strLine.startsWith("AK")) { list.add(strLine);}Iterator itr;for (itr=list.iterator(); itr.hasNext(); ) { String str = itr.next().toString(); String [] splitSt =str.split("\\t"); String junk1 = "\\t";\[/code\]I pulled the iterator part from online, and don't know how to split it there, or how do put the respective values into an array. I'd appreciate any help that you can offer. Thanks!
 
Back
Top