I want to simplify my problem.
I have a table called xenon already populated with some data and i want when a certain button is clicked, the data in the table to be read and and writen in a file myXenon. Below is my code:
|
Code:
|
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
DefaultTableModel model = (DefaultTableModel) Xenon.getModel();
try {
File f = new File("myXenon.txt");
boolean success = f.createNewFile();
if (success) {
//File did not exist and was created
}
else {
//File already exists
}
BufferedWriter out = new BufferedWriter(new FileWriter(f));
this. = Xenon.readData(ROWS_QUANTITY, COLUMNS_QUANTITY);
/*at this point, the program is supposed to read data from the table(Xenon) and write it in the file(myXenon.txt). anyboby with an idea?
*/
out.write();
out.close();
System.out.println("The file myXenon.txt has been created and updated in the current directory");
}
catch (IOException e) {
}
// DefaultTableModel model = (DefaultTableModel) Xenon.getModel();
try {
Vector data = new Vector();
String aLine;
FileInputStream fis = new FileInputStream("myXenon.txt");
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
// BufferedReader in = new BufferedReader(new FileReader("myXenon.txt"));
// read each line of the file
while ((aLine = br.readLine()) != null) {
// create a vector to hold the field values
Vector row = new Vector();
// tokenize line into field values
StringTokenizer st = new StringTokenizer(aLine, "|");
while (st.hasMoreTokens()) {
// add field to the row
row.addElement(st.nextToken());
}
System.out.print(data);
// add row to the model
model.addRow(row);
}
br.close();
fis.close();
} catch (IOException e) {
}
} |