Text file to array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • otorojava
    New Member
    • Jan 2008
    • 8

    #1

    Text file to array

    Hi,
    I'm trying to store values from a text file into my array list

    Code:
    public static ArrayList getAccts(String file)
        { 
        	//Attributes
        	String aRecord;
    	StringTokenizer strings;
        	
            Account anAcct = new Account(); //Intialize obj
    
    	ArrayList<Account> anAL= new ArrayList<Account>();
    		
    	    try
    		{
    			FileReader inStream = new FileReader("myFile.txt");
    	        BufferedReader ins = new BufferedReader(inStream);
    	     
    	      while ((aRecord=ins.readLine())!= null)
    		  {
    	        strings = new StringTokenizer(aRecord,"?"); //toekenizer
    	        if (strings.countTokens() == 2) {
    	          a = strings.nextToken();
    	          b = strings.nextToken();
    	        }
    	      		anAcct = new Account (a,b);
    			anAL.add(anAcct);
    			
    	      }
    	      ins.close();
    	    }
    		 catch(IOException e)
    		 {
    	       e.printStackTrace();
    	     }
    
    		return anAL;
    	}
    My text file has two lines
    Code:
    test1?test1_value?
    test2?test2_value?
    Output incorrectly shows:
    test2 test2_value
    test2 test2_value

    Which I want to show:
    test1 test1_value
    test2 test2_value
  • otorojava
    New Member
    • Jan 2008
    • 8

    #2
    ok, i got it... thanks for looking

    Comment

    Working...