开发者

How to write contents of a JTable to a txt file

开发者 https://www.devze.com 2022-12-28 01:10 出处:网络
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

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 );
   }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号