473,396 Members | 1,914 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,396 software developers and data experts.

Split text and store it in arraylist [ problem with code]

Hello,

Im trying to implement a program which will split a text file and then parses the elements to an arraylist.
My text file looks like that:

Name: Mariah Johnson
Customer no: 663,283
Post code: BA1 74E
Telephone no: 028-372632
Last modified: Jan 11, 2007 8:10:05 PM GMT

Name: Jim Blahblah
Customer no: 863,483
Post code: BA1 64B
Telephone no: 011-342349
Last modified: Jan 27, 2008 1:56:00 AM GMT
My program is that:
Expand|Select|Wrap|Line Numbers
  1. public class Parse {
  2.  
  3. public Parse() {
  4. }
  5.  
  6. public static void main(String[] args) throws java.io.IOException {
  7.  
  8. String line = null;
  9. FileInputStream textfile = new FileInputStream("Customer.txt");
  10. BufferedReader in = new BufferedReader(new InputStreamReader(textfile));
  11. ArrayList custlist = new ArrayList ();
  12. line = null;
  13. while (null != (line = in.readLine())) {
  14.  
  15. StringTokenizer strtok = new StringTokenizer(line);
  16. while (strtok.hasMoreTokens()) {
  17. Date lastModified = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss").parse(strtok.nextToken());
  18. Date lastModified2 = new SimpleDateFormat("HH:mm:ss yyyy-MM-dd").parse(strtok.nextToken());
  19. int i = Integer.parseInt(strtok.nextToken());
  20. //String str = Integer.toString(i);
  21.  
  22.  
  23. custlist s = new custlist(lastModified,lastModified2,i, str);
  24. custlist.add( s);
  25. }
  26. }
  27.  
  28.  
  29.  
  30. }
  31. textfile.close();
  32. }
  33.  
And thats my customer class:


Expand|Select|Wrap|Line Numbers
  1. public class Customer
  2. {
  3. String Name;
  4. double Customer_no;
  5. String post_code;
  6. int telephone_no;
  7. SimpleDateFormat lastModified;
  8.  
  9. public Customer(Date lastModified,
  10. Date lastModified2, int i, String str) {
  11. }
  12. public String getName() {
  13. return Name;
  14. }
  15. public void setName(String name) {
  16. Name = name;
  17. }
  18. public double getCustomer_no() {
  19. return Customer_no;
  20. }
  21. public void setCustomer_no(double customer_no) {
  22. Customer_no = customer_no;
  23. }
  24. public String getPost_code() {
  25. return post_code;
  26. }
  27. public void setPost_code(String post_code) {
  28. this.post_code = post_code;
  29. }
  30. public int getTelephone_no() {
  31. return telephone_no;
  32. }
  33. public void setTelephone_no(int telephone_no) {
  34. this.telephone_no = telephone_no;
  35. }
  36. public SimpleDateFormat getLastModified() {
  37. return lastModified;
  38. }
  39. public void setLastModified(SimpleDateFormat date) {
  40. lastModified = date;
  41. }
  42. public static void add(Customer s) {
  43. }
  44.  

If anyone could help me completing my program/clarifying errors it 'd be grateful !

Thanks in advance!
Feb 24 '08 #1
1 2605
r035198x
13,262 8TB
StringTokenizer is old. Use the String.split method instead.
Feb 25 '08 #2

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

Similar topics

5
by: Stu Cazzo | last post by:
I have the following: String myStringArray; String myString = "98 99 100"; I want to split up myString and put it into myStringArray. If I use this: myStringArray = myString.split(" "); it...
4
by: William Stacey [MVP] | last post by:
Would like help with a (I think) a common regex split example. Thanks for your example in advance. Cheers! Source Data Example: one "two three" four Optional, but would also like to...
7
by: Christine | last post by:
My code has a split function that should split the text file of numbers. I've run this in previous programs as it is here and it worked, but now it wont work for some reason and returns...
7
by: byoxemeek | last post by:
I have an array created from an undelimited text file I receive with a format like: 60190012003010203040506070809101112 60190012004010203040506070809101112 6019001200501020304...
7
by: Jordi Rico | last post by:
Hi, I know I can split a string into an array doing this: Dim s As String()=Regex.Split("One-Two-Three","-") So I would have: s(0)="One" s(1)="Two"
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
12
by: garyusenet | last post by:
string lines = File.ReadAllLines(@"c:\text\history.txt"); foreach (string s in lines) { ArrayList results = new ArrayList(); string delimit = ";"; string currentline = s.Split(";"); ...
12
blazedaces
by: blazedaces | last post by:
Hello again. I'm trying to take as an input an ArrayList<String> and utilize String's .spit(delimiter) method to turn that into a String. I'm getting some kind of error though (I'll post the code...
1
by: mad.scientist.jr | last post by:
I am working in C# ASP.NET framework 1.1 and for some reason Regex.Split isn't working as expected. When trying to split a string, Split is returning an array with the entire string in element ...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.