Hi,
I have a problem that my program is writing only single line from the dataset whereas I want to write whole data from the data file to be read and written on the screen. Somebody help me.
This is my program:
import java.io.*;
import java.util.*;
class QueryAnswering
{
int rowmax = 100;
int colmax = 17;
ArrayList data;
StringTokenizer strTokenizer;
String dataSetFileName = new String("data.txt");
File outputFile;
FileWriter out;
BufferedWriter outbuf;
public void readdata(String line1, int row) {
strTokenizer = new StringTokenizer(line1);
int[] rowData = new int[colmax];
for (int col = 0; col < colmax; col++) {
rowData[col] = Integer.parseInt(strTokenizer.nextToken());
}
data.add(rowData);
}
void readDataFile() {
File inputFile;
FileReader in;
BufferedReader inbuf;
int i = 0;
String line = null;
try {
inputFile = new File(this.dataSetFileName);
in = new FileReader(inputFile);
inbuf = new BufferedReader(in);
if ((rowmax == 0) || (colmax == 0)) {
line = inbuf.readLine();
strTokenizer = new StringTokenizer(line);
rowmax = Integer.parseInt(strTokenizer.nextToken());
colmax = Integer.parseInt(strTokenizer.nextToken());
}
data = new ArrayList();
while (i < rowmax) {
line = inbuf.readLine();
readdata(line, i);
i++;
}
inbuf.close();
in.close();
} catch (Exception ex) {
System.out.println(line + i);
//ex.printStackTrace();
}
}
public static void main(String[] args) throws IOException {
QueryAnswering d = new QueryAnswering();
d.readDataFile();
}
}
Data.txt
republican n y n y y y n n n y ? y y y n y
republican n y n y y y n n n n n y y y n ?
democrat ? y y ? y y n n n n y n y y n n
democrat n y y n ? y n n n n y n y n n y
democrat y y y n y y n n n n y ? y y y y
democrat n y y n y y n n n n n n y y y y
democrat n y n y y y n n n n n n ? y y y