Connect with Facebook Lost Password?


Go Back   CodeCall Programming Forum > Software Development > Java Help

Java Help Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-03-2008, 05:27 AM
Newbie
 
Join Date: Nov 2008
Posts: 6
Rep Power: 0
Manfrizy is an unknown quantity at this point
Red face Reading and writing the contents of jtable into a text file

Hi pple,
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
I have a table(Xenon) already populated with some data and i want when a certain button is clicked, data in the table to be read and writen in a file (myXenon.txt)
My code is as below:

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 table is supposed to be read and the data writen in the file myXenon.Anybody 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) {
   } 
      try {
          Vector data = new Vector();
          String aLine;
          
         FileInputStream fis = new FileInputStream("myXenon.txt");
         BufferedReader br = new BufferedReader(new InputStreamReader(fis));
         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) {
    }
      
}

Last edited by Manfrizy; 12-04-2008 at 02:13 AM.. Reason: Problem siplified
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 12-05-2008, 03:42 PM
Turk4n's Avatar   
Code Warrior
 
Join Date: May 2008
Location: 4chan.org/g/
Age: 19
Posts: 2,714
Blog Entries: 4
Rep Power: 29
Turk4n is a splendid one to beholdTurk4n is a splendid one to beholdTurk4n is a splendid one to beholdTurk4n is a splendid one to beholdTurk4n is a splendid one to beholdTurk4n is a splendid one to behold
Send a message via MSN to Turk4n Send a message via Skype™ to Turk4n
Default Re: Reading and writing the contents of jtable into a text file

Code:
StringTokenizer st = new StringTokenizer(aLine, "|");
         while (st.hasMoreTokens()) {
            // add field to the row
            row.addElement(st.nextToken());
Could you tell me the purpose and function out of this, what is it really doing, not out of the small explanation, just tell me...
__________________
Quote:
Originally Posted by Turk4n
The Last man who laughs, he did not get the joke.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
C# Tutorial: Writing Text Files Xav CSharp Tutorials 44 06-02-2009 06:05 AM
Saving and reading a Text file Sparky Pascal/Delphi 11 12-03-2008 10:27 AM
What mode should i use at fopen()? r, r+, w+b??? tirengarfio C and C++ 3 08-13-2008 11:06 PM
Tutorial: Visual Studio 2008 C# Compressing Jordan CSharp Tutorials 0 05-13-2008 04:52 PM
Issue writing to file: pointer to a class which contains pointers to other classes Sheemer C and C++ 0 08-21-2007 01:17 AM


All times are GMT -5. The time now is 09:12 PM.

Freelance Jobs

XML/XSL: Need code for Book with Chapers using XML
Create an XML file for a book of your creation, and a basic CSS file that will format it to display ...
Earn: $40.00


C++/C: Simple firework cue sequencer
What I require is a rework of a simple cue sequencer. I have a piece of hardware (an Arduino boar...
Earn: $50.00


HTML/XHTML: Menu Rework - ASCIIBin
I'm placing this in the HTML/XHTML section of the Freelance site but you are not limited to HTML. Wh...
Earn: $20.00



CodeCall Goal

Goal #1: 1,000 Blogs
Goal #2: 1,000 Wiki Pages
Goal #3: 300,000 Posts
Goal #4: 20,000 Threads
Done: 30%, 23%, 55%, 75%

Ads