Hello all,
I am attempting to write a program that will read the characters of a text file one by one and keep the count of the number of times each character appears. I would like to use the table data structure "DefaultTableModel"
I would like the table to appear like this
Character/ Frequency
a 10
b 5
c 7
.
.
.
However I am not sure how to use the DefaultTableMode.setColumnIdentifiers method since the identifiers can incerease as the file is read. Here is some of my code
public DefaultTableModel readFile(File filename) throws IOException { BufferedReader reader = new BufferedReader(new FileReader(filename)); DefaultTableModel myDefaultTableModel = new DefaultTableModel(1,1); String line = null; int i = 0; //Determine while(reader.ready()) { line = reader.readLine(); readString(line, myDefaultTableModel, i); i++; } //Close reader object reader.close(); return myDefaultTableModel; } private void readString(String lineString, DefaultTableModel myDefaultTableModel, int i) { Object testObject; StringTokenizer tokenizer = new StringTokenizer(lineString); String token = tokenizer.nextToken(); for (int stringCount = 0; stringCount < token.length(); stringCount++) { myDefaultTableModel.setValueAt(token.charAt(stringCount), 0, 0); testObject = myDefaultTableModel.getValueAt(0, 0); } }