Cómo dividir después del espacio en una línea en el file de text

Estoy tratando de leer un file de text / Excel en JTable . Pero viene en una línea en la fila pero no depende del encabezado. Ni siquiera tengo el encabezado.

 public class TableTest extends JFrame { //create row and col as vector private Vector data; private Vector column; private final JPanel pane; private JTable table; //design the frame public TableTest() throws IOException { //set the title super("Table test"); //set the frame size setSize(400, 400); //make frame visible setVisible(true); //close when click the cross button setDefaultCloseOperation(EXIT_ON_CLOSE); //set display layout setLayout(new BorderLayout()); //create panel to display table pane = new JPanel(); pane.setLayout(new BorderLayout()); //create table table = new JTable(); //add it into panel pane.add(table); //add panel into frame add(pane); readFile(new DefaultTableModel(), table); } //read the file and populate table private void readFile(DefaultTableModel model, JTable table) throws FileNotFoundException, IOException { //create file reference which will be read FileReader reader = new FileReader("C:\\test.xls"); //try buffenetworking reader to read data from file reader try{ //create buffenetworking reader for read string stream BuffenetworkingReader br = new BuffenetworkingReader(reader); //store file data into string String stonetworkingata; column = new Vector(); data = new Vector(); //add the header text of the file menually column.addElement("Day"); column.addElement("Ramadan"); column.addElement("Date"); column.addElement("Sahree"); column.addElement("Ifter"); //get the column name automatically for (int i = 0; i < column.size(); i++) { model.addColumn(column.elementAt(i)); } //read total data from the file and set it into data vector while ((stonetworkingata = br.readLine()) != null) { //add the row data into vector //String value[] = br.readLine().split(","); data.addElement(stonetworkingata); //if found , end of the text then split it into new line use , //if(stonetworkingata.endsWith(",")){ // stonetworkingata.split(","); //continue; //} ListIterator listIterator = data.listIterator(); while(listIterator.hasNext()){ stonetworkingata = (String) listIterator.next(); //System.out.println((stonetworkingata)); } data.addElement(stonetworkingata); //System.out.println(stonetworkingata); //finally add the data into table model model.addRow(data); } //populate data into table table.setModel(model); //refresh the table table.repaint(); //debug System.out.println(column); System.out.println(data); //filanlly close the buffenetworking reader br.close(); } catch(Exception ex){ JOptionPane.showMessageDialog(null, ex, "Error about file reading !", JOptionPane.ERROR_MESSAGE); Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); } } //read the file and populate table private void read(DefaultTableModel model, JTable table) throws FileNotFoundException, IOException { //try buffenetworking reader to read data from file reader try{ column = new Vector(); //add the header text of the file menually column.addElement("Day"); column.addElement("Ramadan"); column.addElement("Date"); column.addElement("Sahree"); column.addElement("Ifter"); //get the column name automatically for (int i = 0; i < column.size(); i++) { column.elementAt(i); model.addColumn(column); } data = new Vector(); data.addElement("col 1"); data.addElement("col 2"); data.addElement("col 3"); data.addElement("col 4"); data.addElement("col 5"); data.addElement("col 6"); data.addElement("col 7"); for(int i = 0; i<data.size(); i++){ data.elementAt(i); model.addRow(data); } //populate data into table table.setModel(model); //refresh the table table.repaint(); //debug System.out.println(column); System.out.println(data); } catch(Exception ex){ JOptionPane.showMessageDialog(null, ex, "Error about file reading !", JOptionPane.ERROR_MESSAGE); Logger.getLogger(TableTest.class.getName()).log(Level.SEVERE, null, ex); } } public static void main(String args[]) throws IOException { TableTest test = new TableTest(); } } 

Para dividir una cadena sobre la base del espacio en blanco, testing

 String.split("\\s"); 

También puedes usar:

  String[] split = StringUtils.split(stringToSplit, " ");