943,152 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 2488
  • Java RSS
Jan 12th, 2010
0

Help: Java Text File Reader

Expand Post »
Im currently working on a project where i need to read a text file containing a list of users and let it be stored in a database.

Here is my text file: headers(ID number, LastName, FirstName, MiddleInitial,Course and Year):

2070939 Carter, Billy Joe K. BSIT 4
2070123 Daniel, Michael Ericson P. BSIT 4
2070432 Jones, Gail D. BSIT 4
2070635 Jones, Julia Marie L. BSIT 4
2072782 Tarver, Sonny J. BSIT 4

I need to extract them per column and insert them into different arrays. In my code below i extracted the id numbers and the last names. My problem now is reading the first names along with the MI's,courses and years.

The preferred output must be:

2070939
Carter
Billy Joe
K
BSIT
4
...

Thank you for reading my post.. Im hoping you could give your opinions/suggestions regarding my matter..
Java Syntax (Toggle Plain Text)
  1. FileInputStream fstream = new FileInputStream("text.txt");
  2. DataInputStream in = new DataInputStream(fstream);
  3. BufferedReader br = new BufferedReader(new InputStreamReader(in));
  4. String strLine;
  5. String idNum, lastName, GivenName, mI, course, yr;
  6. String[] temp, temp2;
  7. String space = " ";
  8. String comma = ",";
  9. String period = ".";
  10.  
  11. while ((strLine = br.readLine()) != null) {
  12.  
  13. if(strLine.contains(comma)){
  14. temp = strLine.split(comma);
  15. String s = temp[0];
  16. temp = s.split(space);
  17. idNum = temp[0];
  18. lastName = temp[1];
  19. System.out.print(temp[0]);
  20. System.out.print(temp[1]);
  21. }

My output:
2070939
Carter
2070123
Daniel
2070432
Jones
2070635
Jones
2072782
Tarver
Last edited by sleaze; Jan 12th, 2010 at 10:53 am. Reason: Moved to forums from code snippet
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
sleaze is offline Offline
1 posts
since Jan 2010
Jan 12th, 2010
0
Re: Help: Java Text File Reader
Please post your question as a forum thread and not a code snippet. Also, try pasting your code again given that your code got eaten up when moving this thread from code snippets section to forums.
Super Moderator
Featured Poster
Reputation Points: 3233
Solved Threads: 719
Failure as a human
~s.o.s~ is offline Offline
8,871 posts
since Jun 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Need help with java program for online computer shop
Next Thread in Java Forum Timeline: how to search a word in a text file ??





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC