i have a mydata.txt file with this in it:
B.Friedel 38 LRC usa 20 1 1 1 21 410 300 300 300 18 0 1673 0 76 26 0 0 0 0 0 0 0 0
M.Fulop 26 LRC hun 17 1 1 1 26 308 300 300 300 1 1 16 0 1 0 0 0 0 0 0 0 0 0
B.Guzan 25 LRC usa 15 1 1 1 23 300 300 300 300 0 0 0 0 0 0 0 0 0 0 0 0 0 0
M.Laursen 32 C den 1 24 6 12 25 300 493 409 373 17 0 1619 0 0 0 17 7 15 2 0 14 0 0
C.Davies 24 C eng 1 23 9 6 25 300 302 430 304 15 0 1457 0 0 0 8 9 6 0 0 4 0 0
C.Cuellar 28 RC esp 1 23 12 8 24 300 302 412 320 14 1 1273 0 0 0 10 10 13 0 0 8 0 0
L.Young 30 RC eng 1 23 10 6 22 280 328 435 316 11 1 1006 0 0 2 14 9 5 0 0 0 0 0
N.Shorey 28 L eng 1 23 8 4 22 300 312 353 312 14 0 1367 0 0 0 10 2 7 0 1 8 0 0
W.Bouma 31 L ned 1 22 14 12 23 300 504 358 301 4 0 378 0 0 0 4 6 3 0 0 8 0 0
J.Collison 21 RC wal 1 9 21 9 21 300 296 754 320 9 0 771 0 0 0 1 15 11 0 1 0 0 0
i need to read this text file, and put the information into a JTable so that then i can sort the information alphabetically.
JTable needs to have these columns: Name Age Prs Nat St Tk Ps Sh Ag KAb TAb PAb SAb Gam Sub Min Mom Sav Con Ktk Kps Sht Gls Ass DP Inj Sus
under neath these columns i need the information from the .txt file to fall under its right catgory.
i was told i need to read the text line by line, put it into an arraylist and then split the lines up at every " " <-- space and put that into a JTable
my code so far:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;
public class rosterSorter
{
public static void main()
{
BufferedReader br = null;
ArrayList rosterList = new ArrayList();
try
{
br = new BufferedReader(new FileReader("mydata.txt"));
String line = br.readLine();
String [] rowfields = line.split(" ");
while (line != null )
{
rosterList.add(line);
line = br.readLine();
}
}
catch (FileNotFoundException e)
{
// can be thrown when creating the FileReader/BufferedReader
// deal with the exception
e.printStackTrace();
}
catch (IOException e)
{
// can be thrown by br.readLine()
// deal with the exception
e.printStackTrace();
}
show(rosterList);
}
public static void show(ArrayList rosterList){
for (int i = 0; i < rosterList.size(); i++)
{
System.out.println(rosterList.get(i));
}
}
}
the method show is only used for my testing to see if it works, the program outputs the original .txt to the terminal but not the split one, how would i split it and get to output the split up text to the terminal?
thanks in advance.