I want to ask about how to write data to file .txt or .dat, etc line by line
please give me the source code
Message was edited by: anindita
/**There are a variety of ways to get this done.
*Your approach will depend largely on your data source
*Let's approach it from this angle.let's get data from a jtable instance and write *each row of the table data per line in our destination file
//File may be one selected by user by means of a filechooser
File file = ........
JTable table = ........
if(table != null && file != null)
PrintWriter writer = null;
TableModel model = table.getModel();
writer = new PrintWriter(new BufferedWriter(new FileWriter(file, true)));
for(int i = 0; i < model.getRowCount(); ++i)
for(int j = 0; model.getColumnCount(); ++j)
//write each row of table data per line in destination file
writer.print(model.getValueAt(i,j).toString + " ");
//Move insertion point to next line in destination file
//Handle exception here
if(writer != null)
Your use of this web site or any of its content or software indicates your agreement to be bound by these Terms of Participation.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. Oracle and Java are registered trademarks of Oracle and/or its affiliates. Other names may be trademarks of their respective owners.