Swing - JTable to txt file

Hi...Can someone provide me a simple way to save my jtable's data into a text file.A lot of methods i tried were bugy...Thanx
[166 byte] By [jNathara] at [2007-11-26 23:08:43]
# 1
I don't think there are any clever shortcuts.1. Use method getValueAt of JTable or TableModel (being aware that columns may have been filtered out or rearranged)2. Turn the value objects into strings, as you see fit.3. Write these strings to a text file.
DrLaszloJamfa at 2007-7-10 14:03:30 > top of Java-index,Desktop,Core GUI APIs...
# 2
A lot of methods i tried were bugy...That helps us a lot.
camickra at 2007-7-10 14:03:30 > top of Java-index,Desktop,Core GUI APIs...
# 3

ok ....this one did the work

public void saveJTableToFile( JTable table ) {

int returnVal = chooser.showSaveDialog(this);

if (returnVal == JFileChooser.APPROVE_OPTION) {

try {

FileWriter fwriter = new FileWriter(chooser.getSelectedFile());

BufferedWriter bwriter = new BufferedWriter(fwriter);

for (int i=0;i<table.getRowCount();i++) {

for (int j=0;j<table.getColumnCount();j++) {

bwriter.write( String.valueOf( table.getValueAt(i,j) )+"" );

}

bwriter.newLine();

}

bwriter.close();

} catch (IOException ioe){

ioe.printStackTrace();

}

}

}

jNathara at 2007-7-10 14:03:30 > top of Java-index,Desktop,Core GUI APIs...