Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8734167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:47:14+00:00 2026-06-13T09:47:14+00:00

I have a code that reads a multiple text files from a folder and

  • 0

I have a code that reads a multiple text files from a folder and I need to put them in a table.So far,everything is good except that every line from my text files are displayed in a different table.I know that the problem is that the table receives each line separately.I tried to create an object and fill it and then call inside the table but I couldn’t make it work so if anyone can tell me the solution that would be great. Also I need to be able to compare the values and find an average,so if you have any tips for that to,would be great

here’s an example of my text file

17/10/2012 10:00:06.67 [RX] - E usbR<LF>
817EE765FF53-53<LF>
817AA765FF53-34<LF>
817CC765FF53-25<LF>
00<LF>
E qEnd<LF>

and this is what I need to get in the table

    ID             RSSI
817EE765FF53        53
817AA765FF53        34
817CC765FF53        25

here is the code

import java.awt.BorderLayout;
import java.io.*;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;

public class Foldersearch1

{

  public static void main(String[] args) 
  {
    // Directory path here
    String path = "C:/Users/Nikica/Desktop/text files"; 

    String files;
    File folder = new File(path);
    File[] listOfFiles = folder.listFiles(); 

    for (int i = 0; i < listOfFiles.length; i++) 
    {
      if (listOfFiles[i].isFile()) 
      {
        files = listOfFiles[i].getName();
        if (files.endsWith(".txt") || files.endsWith(".TXT"))
        {

          System.out.println(files);
          (); 

          String currentLine="";

          File textFile = new File(folder.getAbsolutePath() + File.separator + files); 
          try{
            // Open the file that is the first 
            // command line parameter
            FileInputStream fstream = new FileInputStream(textFile);
            try (DataInputStream in = new DataInputStream(fstream)) {
              BufferedReader br = new BufferedReader(new         InputStreamReader(in));
              String strLine;
              String line;
              //Read File Line By Line
              // int p=0;
              // Object[][] Table=null;
              while ((strLine = br.readLine()) != null)   {
                processLine(strLine);
                Table(strLine);

                // Print the content on the console
                //System.out.println (strLine);
              }


            }
          }catch (Exception e){//Catch exception if any
            System.err.println("Error: " + e.getMessage());
          }
        }
      }
    }
  }
  public static void processLine(String line) {
    // skip header & footer


    if (line.startsWith("17/10/2012 10:00:06.67 [RX] - E usbR<LF>") || line.startsWith("E qEnd<LF>")) {return;}


    String ID = line.substring(0, 12);
    String RSSI = line.substring(13, 15);


    System.out.println("ID [" + ID + "]\t RSSI [" + RSSI +"]");

  }
  public static void Table(String line) {
    JFrame frame = new JFrame("proba");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    if (line.startsWith("17/10/2012 10:00:06.67 [RX] - E usbR<LF>") || line.startsWith("E qEnd<LF>")) return;
    String ID = line.substring(0, 12);
    String RSSI = line.substring(13, 15);

    Object rowData[][] = { { ID, RSSI } };
    Object columnNames[] = { "ID", "RSSI" };
    JTable table = new JTable(rowData, columnNames);

    JScrollPane scrollPane = new JScrollPane(table);
    frame.add(scrollPane, BorderLayout.CENTER);
    frame.setSize(300, 150);
    frame.setVisible(true);
  }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T09:47:15+00:00Added an answer on June 13, 2026 at 9:47 am

    To make your code work with minimal changes, Create a Vector with the rowdata, and use the constructor public JTable(Vector rowData, Vector columnNames). The following code snippet should give you an idea on how to do it.

    Vector<String> columnNames = new Vector<String>();
    columnNames.add("ID");
    columnNames.add("RSSI");
    
    Vector<Vector<String>> rowData = new Vector<Vector<String>>();
    
    for(int i=0; i<20; i++) {
        Vector<String> row = new Vector<String>();
        row.add("ID_" + i);
        row.add("RSSI_" + i);
        rowData.add(row);
    }
    
    JTable table = new JTable(rowData, columnNames);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a section of code that I need to remove from multiple files
We have some C# code that reads data from a text file using a
so i have code that reads from an AVAsset using kCVPixelFormat_32BGRA. I get the
I have this code that reads from XML file. It gets five strings (groupId,
I have a simple java code that reads text csv file that contains sentences
I have the following piece of Java code that reads strings from CSV file.
I have a simple application that reads data in small strings from large text
I have this Jquery code, that will remove color from the text if the
In my .aspx.cs I have a code that reads a .xml file and I
I have the following code that reads the content of a url public static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.