Results 1 to 5 of 5
Thread: want to save JTable in a file..
- 04-08-2010, 04:24 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 48
- Rep Power
- 0
want to save JTable in a file..
i am trying to save JTable in a file..
which file type is appropriate for this ?
i used txt/xls/doc.....etcJava Code:table=new JTable(model); if (classNameBox.getState()==true){ File directory = new File("C:/Java/Class"); directory.mkdirs(); File file=new File(directory, "newfile.txt"); file.createNewFile(); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(file)); oos.writeObject(table); oos.close();
i am getting strange output.. how can i get right output?what we are thinking, it might not be true
-
You're writing out binary data. Don't try to open the file and view it and expect to see anything but binary data. To make sense out of the data, you need to open your file with an ObjectInputStream.
Having said this, you still may be better off writing out either the model or the data underlying the model rather than the JTable itself.
- 04-08-2010, 08:56 PM #3
- 04-10-2010, 05:51 AM #4
Member
- Join Date
- Apr 2010
- Posts
- 10
- Rep Power
- 0
As the previous said... your writing binary data.
You have to get the String of the contents of the JTable. I don't know but you should be able to use something in the vicinity of
Then you just need to write that string to the file.Java Code:String.parseString(JTable);
- 04-10-2010, 08:37 AM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Did you check what you have written? I guess not because it doesn't make any sense at all. The OP needs to get the TableModel from the JTable. The Model has methods getColumnCount() and getRowCount() as well as a getValueAt( ... ) method. The OP should use those to fetch the data from the model and write it to a file.
kind regards,
Jos
Similar Threads
-
save file based on file extension
By masa in forum AWT / SwingReplies: 4Last Post: 05-11-2010, 11:17 AM -
How to show or open a file download or file save dialog box
By java_bond in forum New To JavaReplies: 0Last Post: 03-05-2010, 04:21 AM -
Save JTable Data
By anilkumar_vist in forum New To JavaReplies: 0Last Post: 02-08-2010, 12:11 PM -
Save file
By dejos456 in forum New To JavaReplies: 4Last Post: 11-28-2009, 03:13 PM -
how to save file..
By jont717 in forum New To JavaReplies: 2Last Post: 02-12-2009, 11:33 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks