+ Reply to Thread
Results 1 to 2 of 2

Thread: Reading and writing the contents of jtable into a text file

  1. #1
    Newbie Manfrizy is an unknown quantity at this point
    Join Date
    Nov 2008
    Posts
    6

    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

  2. #2
    Code Warrior Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n has much to be proud of Turk4n's Avatar
    Join Date
    May 2008
    Location
    4chan.org/g/
    Age
    20
    Posts
    3,836
    Blog Entries
    4

    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...

    Hatsune Miku ~❤❤❤
    初音ミク。~❤❤❤

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. Tutorial: Visual Studio 2008 C# Compressing
    By Jordan in forum CSharp Tutorials
    Replies: 5
    Last Post: 08-30-2009, 07:25 AM
  2. C# Tutorial: Writing Text Files
    By Xav in forum CSharp Tutorials
    Replies: 46
    Last Post: 07-28-2009, 08:18 AM
  3. Saving and reading a Text file
    By Sparky in forum Pascal/Delphi
    Replies: 11
    Last Post: 12-03-2008, 10:27 AM
  4. What mode should i use at fopen()? r, r+, w+b???
    By tirengarfio in forum C and C++
    Replies: 3
    Last Post: 08-13-2008, 11:06 PM
  5. Replies: 0
    Last Post: 08-21-2007, 01:17 AM

Bookmarks

Bookmarks

     
        Algorithms and Data Structures

        Java tutorials

        Algorithms Forum

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts