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..

FileInputStream fstream = new FileInputStream("text.txt");
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));
    String strLine;
	String idNum, lastName, GivenName, mI, course, yr;
	String[] temp, temp2;
    String space = " ";
    String comma = ",";
    String period = ".";
    
    while ((strLine = br.readLine()) != null)   {
		
    		if(strLine.contains(comma)){	
				temp = strLine.split(comma);
				String s = temp[0];
				temp = s.split(space);
				idNum = temp[0];
				lastName = temp[1];			
				System.out.print(temp[0]);	
				System.out.print(temp[1]);								
   					}

My output:
2070939
Carter
2070123
Daniel
2070432
Jones
2070635
Jones
2072782
Tarver

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.