473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Text file to array

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

Expand|Select|Wrap|Line Numbers
  1. public static ArrayList getAccts(String file)
  2.     { 
  3.         //Attributes
  4.         String aRecord;
  5.     StringTokenizer strings;
  6.  
  7.         Account anAcct = new Account(); //Intialize obj
  8.  
  9.     ArrayList<Account> anAL= new ArrayList<Account>();
  10.  
  11.         try
  12.         {
  13.             FileReader inStream = new FileReader("myFile.txt");
  14.             BufferedReader ins = new BufferedReader(inStream);
  15.  
  16.           while ((aRecord=ins.readLine())!= null)
  17.           {
  18.             strings = new StringTokenizer(aRecord,"?"); //toekenizer
  19.             if (strings.countTokens() == 2) {
  20.               a = strings.nextToken();
  21.               b = strings.nextToken();
  22.             }
  23.                   anAcct = new Account (a,b);
  24.             anAL.add(anAcct);
  25.  
  26.           }
  27.           ins.close();
  28.         }
  29.          catch(IOException e)
  30.          {
  31.            e.printStackTrace();
  32.          }
  33.  
  34.         return anAL;
  35.     }
My text file has two lines
Expand|Select|Wrap|Line Numbers
  1. test1?test1_value?
  2. test2?test2_value?
Output incorrectly shows:
test2 test2_value
test2 test2_value

Which I want to show:
test1 test1_value
test2 test2_value
Jan 30 '08 #1
1 1538
ok, i got it... thanks for looking
Jan 30 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Paul C-T | last post by:
Hi, Am I trying to be too clever here? I am trying to write a PHP page to enable me to enter values into a form then write those values to a text file. I want to use the form & table that...
5
by: Andrew V. Romero | last post by:
At work we have an excel file that contains the list of medications and their corresponding strengths. I would like to save the excel file as a text list and paste this list into a javascript...
8
by: Yeow | last post by:
hello, i was trying to use the fread function on SunOS and ran into some trouble. i made a simple test as follows: i'm trying to read in a binary file (generated from a fortran code) that...
2
by: Dan Pearce | last post by:
I have a text file called test.txt which is I am trying to get to load into a webpage. This is simple enough, but I am trying to make it so that it recognises certain formatting, similar to how...
3
by: OliveOyl3471 | last post by:
In Visual Basic.NET 2003, how do you populate a two dimensional array from a text file? I know how to check file existence, open the file for read, etc. I just can't get it to read more than one...
4
by: alnoir | last post by:
I'm writing a script that take web pages and stores the content into an array. Before, I was looping through a text file and stored each line into an array. With a file I could read it by line and...
13
by: rohit | last post by:
Hi All, I am new to C language.I want to read integers from a text file and want to do some operation in the main program.To be more specific I need to multiply each of these integers with another...
5
by: dm3281 | last post by:
Hello, I have a text report from a mainframe that I need to parse. The report has about a 2580 byte header that contains binary information (garbage for the most part); although there are a...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.