How to write contents of a JTable to a txt file
I wonder if anyone could kindly tell me how to write the contents of a J开发者_如何转开发Table to a .txt file. I have a basic knowledge of java and know about FileReaders etc, but just don't know how to do something as complicated as this. Thanks-please could you also provide a bit of sample code. Thanks again
It will be something like the below. I wrote the below off the top of my head but I think it is right.
Regards,
Guido
TableModel model = table.getTableModel();
for( int i = 0; i < model.getRowCount(); i++ )
{
for( int i = 0; i < model.getColumnCount(); j++ )
{
//Create your File Writer
fileWriter.write( model.getValueAt( i, j );
}
}
精彩评论