Return to Snippet

Revision: 65164
at November 8, 2013 02:47 by bluesh34


Updated Code
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;
	

	}

}

Revision: 65163
at November 2, 2013 23:51 by bluesh34


Updated Code
package xmlReader;

/*

Integer i = new Integer(1);

Integer[] In = new Integer[3];

In[1] = i;

int j = 1357;

int d = j%60;

System.out.println(d);

*/

//Files file = new Files();

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(String FileName)
    public CapitalsReader()
	{
            
            // pass the input parameters to the corresponding fields
            
           // this.fileName=FileName;
            
      
            
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		
		CapitalsReader capitals_reader = new CapitalsReader(); 
		
		capitals_reader.Read(); 
		
		System.out.println("End");
		
	}
	
	public String [][] Read()
	{  
		
		try {
			
			//File c = new File("C:/Users/User/Capitals.xml"); 
			
			//c.setReadable(true);
			
		
			//String fileName = "C:/Users/User/Capitals.xml/Capitals.xml";
			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)
			{
			
				// if lineNumber == 0, skip line and increment lineNumber, 
				// or else just increment lineNumber 
				
				lineNumber++;
				
				tokenNumber = 0;
				
				// skip second line
				
				if(lineNumber!=1)
					
				{
				
					StringTokenizer stringTokenizer = new  StringTokenizer(fileName);
				
					while (stringTokenizer.hasMoreTokens())
					
					{
						
						String token = stringTokenizer.nextToken();
						
						//if()
						
						//System.out.println("lineNumber: "+lineNumber);
						
						
						
						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;
	

	}

}

Revision: 65162
at November 2, 2013 22:58 by bluesh34


Initial Code
package xmlReader;

/*

Integer i = new Integer(1);

Integer[] In = new Integer[3];

In[1] = i;

int j = 1357;

int d = j%60;

System.out.println(d);

*/

//Files file = new Files();

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];
    
    //public CapitalsReader(String FileName)
    public CapitalsReader()
	{
            
            // pass the input parameters to the corresponding fields
            
           // this.fileName=FileName;
            
      
            
    }

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		
		
		CapitalsReader capitals_reader = new CapitalsReader(); 
		
		capitals_reader.Read(); 
		
		System.out.println("End");
		
	}
	
	public String [][] Read()
	{  
		
		try {
			
			//File c = new File("C:/Users/User/Capitals.xml"); 
			
			//c.setReadable(true);
			
		
			String fileName = "C:/Users/User/Capitals.xml/Capitals.xml";
			BufferedReader br = new BufferedReader( new FileReader(fileName));
				
			int lineNumber = 0; int tokenNumber = 0;
			
			while( (fileName = br.readLine()) != null)
			{
			
				// if lineNumber == 0, skip line and increment lineNumber, 
				// or else just increment lineNumber 
				
				lineNumber++;
				
				// skip second line
				
				if(lineNumber!=1)
					
				{
				
					StringTokenizer stringTokenizer = new  StringTokenizer(fileName);
				
					while (stringTokenizer.hasMoreTokens())
					
					{
						
						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.					
						*/
						
						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;
	

	}

}

Initial URL
https://github.com/mledoze/countries/blob/master/countries.xml

Initial Description
Stores country name code and capital in an array and returns it. (not completed)

Initial Title
capitals.xml XML Reader

Initial Tags
xml

Initial Language
Java