Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-03-2008, 09:06 AM
Manfizy's Avatar
Senior Member
 
Join Date: Nov 2008
Location: Germany
Posts: 165
Rep Power: 2
Manfizy is on a distinguished road
Send a message via Yahoo to Manfizy
Post Reading and writing the contents of jtable into a text file
Hi!
Can anybody tell me how can contents of JTable be written into txt file and read from txt file back to new JTable using IO streams.Please help me if anybody knows.
Thanks.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-04-2008, 09:59 AM
Manfizy's Avatar
Senior Member
 
Join Date: Nov 2008
Location: Germany
Posts: 165
Rep Power: 2
Manfizy is on a distinguished road
Send a message via Yahoo to Manfizy
Question
I want to simplify my problem.
I have a table called xenon already populated with some data and i want when a certain button is clicked, the data in the table to be read and and writen in a file myXenon. Below is my code:

Code:
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
   DefaultTableModel model = (DefaultTableModel) Xenon.getModel();
      try {
          File f = new File("myXenon.txt");  
          boolean success = f.createNewFile();
      if (success) {
      //File did not exist and was created 
      }
         else {
      //File already exists    
    }  
      BufferedWriter out = new BufferedWriter(new FileWriter(f)); 
       this. = Xenon.readData(ROWS_QUANTITY, COLUMNS_QUANTITY);


/*at this point, the program is supposed to read data from the table(Xenon) and write it in the file(myXenon.txt). anyboby with an idea?     
*/

              
         out.write();   
         out.close();
      System.out.println("The file myXenon.txt has been created and updated in the current directory");   
        }        
catch (IOException e) {
   } 
      // DefaultTableModel model = (DefaultTableModel) Xenon.getModel();

      try {
          Vector data = new Vector();
          String aLine;
          
         FileInputStream fis = new FileInputStream("myXenon.txt");
         BufferedReader br = new BufferedReader(new InputStreamReader(fis));
 // BufferedReader in = new BufferedReader(new FileReader("myXenon.txt"));
          // read each line of the file
      while ((aLine = br.readLine()) != null) {
      
         // create a vector to hold the field values
         Vector row = new Vector();

        // tokenize line into field values
         StringTokenizer st = new StringTokenizer(aLine, "|");
         while (st.hasMoreTokens()) {
            // add field to the row
            row.addElement(st.nextToken());
         }

            System.out.print(data);
            // add row to the model
             model.addRow(row);

        }
        br.close();
        fis.close();
    } catch (IOException e) {
    }
      
}
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-04-2008, 10:13 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,446
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
Ok what happen when you try to get data from the JTable? Did you try anything yet?

__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-04-2008, 10:27 AM
Manfizy's Avatar
Senior Member
 
Join Date: Nov 2008
Location: Germany
Posts: 165
Rep Power: 2
Manfizy is on a distinguished road
Send a message via Yahoo to Manfizy
Default
Originally Posted by Eranga View Post
Ok what happen when you try to get data from the JTable? Did you try anything yet?

Am so new to java and i really dont know what to there.Tried suching in the internet but i didnt get. Do you have an idea?As in how to call the table and read the data?
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 12-04-2008, 10:36 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,446
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
If you are new to Java, and new to JTable, best thing is work on a separate application to add data to a JTable and get data from it. Later you can integrate on your real application.

Read this page.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 12-12-2008, 11:46 AM
Manfizy's Avatar
Senior Member
 
Join Date: Nov 2008
Location: Germany
Posts: 165
Rep Power: 2
Manfizy is on a distinguished road
Send a message via Yahoo to Manfizy
Post
i have read the whole tutorial but still i cant find anything to help me solve this problem. I just need a simple method to do this right
105 views and no single solution!!!C´mon pple!
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 12-12-2008, 04:35 PM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 7,446
Rep Power: 11
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
Default
If you have read the page I've send to you, all what you need is there. Read each cell from the file, and make the result as you wish. Then write them to the file.

Originally Posted by Manfizy View Post
105 views and no single solution!!!C´mon pple!
Keep in mind that no one wants to do your homework. If you get any errors post them here and explain your question with the attempt you made. As I said earlier if you read that page, solution is there. Once a member looking at this thread not outline that he/she comment on this.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
Someone helped you? their helpful post.
Help:Forums FAQ|How To Ask Questions The Smart WayResources:The Java Tutorials|Glossary for Java|NetBeans IDE|Sun DownloadsWeb:WritOnceTips:Is your IDE the best?|Which Application Server?
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

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

BB 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
Reading and Writing Text Files kandt New To Java 1 11-12-2008 04:15 AM
swapping the contents of the file and writing to another file Ms.Ranjan New To Java 9 07-10-2008 05:52 PM
Reading file contents (BufferedReader) Java Tip Java Tips 0 02-07-2008 10:00 AM
problems trying to view the contents of a text file in JTextArea warship New To Java 1 07-19-2007 12:20 AM
viewing the contents of a text file in JTextArea warship New To Java 0 07-17-2007 03:29 PM


All times are GMT +2. The time now is 09:27 PM.



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