Hi guys,
I'm making a class for importing a table from a text file with tab delimited data.
It works perfectly as long as there are no empty cells in the text file.
(see attached example)
Any suggestions how to detect an empty cell and what to fill the ArrayList with if the cell is empty?
public class ImportFileTableModel extends AbstractTableModel {
protected ArrayList data;
protected ArrayList columnNames ;
protected String datafile;
public ImportFileTableModel(String f){
datafile = f;
initArrayLists();
}
public void initArrayLists() {
String aLine ;
data = new ArrayList();
columnNames = new ArrayList();
try {
FileInputStream fin = new FileInputStream(datafile);
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
// extract column names
StringTokenizer st1 = new StringTokenizer(br.readLine(), "\t");
while(st1.hasMoreTokens()) columnNames.add(st1.nextToken());
// extract data
while ((aLine = br.readLine()) != null) {
StringTokenizer st2 = new StringTokenizer(aLine, "\t");
while(st2.hasMoreTokens()) data.add(st2.nextToken());
}
br.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public int getRowCount() {
return data.size() / getColumnCount();
}
public int getColumnCount(){
return columnNames.size();
}