Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-17-2007, 05:15 PM
Member
 
Join Date: Dec 2007
Posts: 2
Tzaphiel is on a distinguished road
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 0Billing.data[0].lengthi++){;
                          
dos.writeChars(table.getValueAt(i0).toString().trim());
                          
dos.writeChars("\t");
                          
dos.writeChars(table.getValueAt(i1).toString().trim());
                          
dos.writeChars("\t");
                          
dos.writeChars(table.getValueAt(i2).toString().trim());
                          
dos.writeChars("\t");
                          
dos.writeChars(table.getValueAt(i3).toString().trim());
                          
dos.writeChars("\t");
                          
dos.writeChars(table.getValueAt(i4).toString().trim());
                          
dos.writeChars("\t");
                          
dos.writeChars(table.getValueAt(i5).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 
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] JTable DataModel - how to get AZMichael AWT / Swing 3 07-09-2008 09:27 AM
ResultSet to JTable Java Tip Java Tips 0 02-11-2008 10:01 AM
How to add in a new row in Jtable? Ry4n AWT / Swing 0 01-18-2008 01:26 PM
Help with JTable fernando AWT / Swing 1 08-07-2007 07:57 AM
header of jtable bbq AWT / Swing 1 07-05-2007 05:11 AM


All times are GMT +3. The time now is 10:29 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org