Results 1 to 2 of 2
Thread: JTable to txt File
- 12-17-2007, 04:15 PM #1
Member
- Join Date
- Dec 2007
- Posts
- 2
- Rep Power
- 0
JTable to txt File
Hi - I am relatively new to Java and was wondering if anyone could help me with the following issue. I am trying to write a JTable to a txt file, and have the JTable also be able to read the txt file. The problem is that it is writing the letters with a square symbol between each of them and therefore is unable to then read them back into the JTable. Here is my code for saving the file.
Thanks!
PHP Code:public void saveFile() { File file = null; JFileChooser fc = new JFileChooser(); fc.setCurrentDirectory (new File (".")); int result = fc.showSaveDialog (this); if (result == JFileChooser.APPROVE_OPTION) { file = fc.getSelectedFile(); if (file.exists ()) { int response = JOptionPane.showConfirmDialog (null, "Overwrite existing file?","Confirm Overwrite", JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE); FileOutputStream fos; DataOutputStream dos; try { fos = new FileOutputStream(file); dos = new DataOutputStream(fos); for (int i = 0; i < Billing.data[0].length; i++){; dos.writeChars(table.getValueAt(i, 0).toString().trim()); dos.writeChars("\t"); dos.writeChars(table.getValueAt(i, 1).toString().trim()); dos.writeChars("\t"); dos.writeChars(table.getValueAt(i, 2).toString().trim()); dos.writeChars("\t"); dos.writeChars(table.getValueAt(i, 3).toString().trim()); dos.writeChars("\t"); dos.writeChars(table.getValueAt(i, 4).toString().trim()); dos.writeChars("\t"); dos.writeChars(table.getValueAt(i, 5).toString().trim()); dos.writeChars("\n"); } // end for } // end try catch (IOException e) { System.err.println(e.getMessage()); } // end catch } // end inner if else fc.cancelSelection(); } // end outer if } // end method saveFile
- 04-17-2010, 11:47 AM #2
Member
- Join Date
- Apr 2010
- Posts
- 1
- Rep Power
- 0
Similar Threads
-
[SOLVED] JTable DataModel - how to get
By AZMichael in forum AWT / SwingReplies: 3Last Post: 07-09-2008, 08:27 AM -
ResultSet to JTable
By Java Tip in forum Java TipReplies: 0Last Post: 02-11-2008, 09:01 AM -
How to add in a new row in Jtable?
By Ry4n in forum AWT / SwingReplies: 0Last Post: 01-18-2008, 12:26 PM -
Help with JTable
By fernando in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 06:57 AM -
header of jtable
By bbq in forum AWT / SwingReplies: 1Last Post: 07-05-2007, 04:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks