Jump to content

Recent Topics

Recent Status Updates

  • Photo
      15 Nov

    Hi, I am final year Interior Design Student from University of Huddersfield. I am currently working on my final major project which is going to be linked to coding. I was hoping that you could help me with my research. I have prepared a short survey, it would be a massive help if you could fill it in for me. It takes less than 2 minutes to complete, I promise. Here is the link: https://www.surveymonkey.com/s/73XLJKK Thank you so much in advance!

View All Updates

Developed by TechBiz Xccelerator
- - - - -

Reading and writing the contents of jtable into a text file

  • Please log in to reply
1 reply to this topic

#1 Manfrizy


    CC Lurker

  • Just Joined
  • Pip
  • 6 posts

Posted 03 December 2008 - 03:27 AM

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

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? */

      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
            // add row to the model
    } catch (IOException e) {

Edited by Manfrizy, 04 December 2008 - 12:13 AM.
Problem siplified

  • 0

#2 Turk4n



  • Expert Member
  • PipPipPipPipPipPipPip
  • 1,919 posts
  • Location:Sweden
  • Programming Language:C, Java, PHP, Python, Bash
  • Learning:C++, C#, JavaScript, Visual Basic .NET, Others

Posted 05 December 2008 - 01:42 PM

StringTokenizer st = new StringTokenizer(aLine, "|");
         while (st.hasMoreTokens()) {
            // add field to the row
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...
  • 0

Powered by binpress