# Posted By

bluesh34 on 11/02/13

# Statistics

Viewed 458 times
Favorited by 0 user(s)

# Related snippets

/ Published in: Java
`package xmlReader; import java.io.BufferedReader;import java.io.File;import java.io.FileNotFoundException;import java.io.FilePermission;import java.io.FileReader;import java.io.IOException;import java.nio.file.Files;import java.util.StringTokenizer; public class CapitalsReader { 	String fileName; 	String [][] capitals = new String[249][3]; 	int quoteCount = 0;     public CapitalsReader()	{      } 	public static void main(String[] args) { 		CapitalsReader capitals_reader = new CapitalsReader();  		capitals_reader.Read();  		System.out.println("End"); 	} 	public String [][] Read()	{   		try { 			String fileName ="C:/Users/User/workspace/se5/src/xmlReader/Capitals.xml";			BufferedReader br = new BufferedReader( new FileReader(fileName)); 			int lineNumber = 0; int tokenNumber = 0; 			while( (fileName = br.readLine()) != null)			{ 				lineNumber++; 				tokenNumber = 0; 				// skip second line 				if(lineNumber!=1) 				{ 					StringTokenizer stringTokenizer = new  StringTokenizer(fileName); 					while (stringTokenizer.hasMoreTokens()) 					{ 						String token = stringTokenizer.nextToken(); 						if(tokenNumber == 0 && lineNumber ==4) 						{								System.out.println("tokenNumber: "+tokenNumber);							System.out.println("token: "+token);						}   						tokenNumber++; 						/*						TO DO code to check for the tokens you want so you						can insert the correct elements into the String [][]						capitals. Use the fact that the country name begins						after the first " and ends at the second, the country						code runs from the fifth " to the 6th and the capital 						from the 15th " to the 16th. Once you've processed the 						capital, break ou of the while loop.											*/ 						//if() 						break;					} 					lineNumber++; 				} 			} 		} catch (FileNotFoundException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} catch (IOException e) {			// TODO Auto-generated catch block			e.printStackTrace();		} 		finally		{			// do whatever you want here i.e. print something like "finished"		}		return capitals;  	} }`