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

  • SEARCH
  • Home
  • 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 3616116
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T22:27:35+00:00 2026-05-18T22:27:35+00:00

hey i have text file shown as below. 11/2/2010     cat    6 11/2/2010   

  • 0

hey
i have text file shown as below.
11/2/2010     cat    6
11/2/2010     cat    3
11/2/2010     dog    4
11/2/2010     cat    11
11/3/2010     cat    1
11/3/2010     dog    3
11/3/2010     cat    8

i have in every month this kind of text file. Above figure shows the part of  the text file. so then i want to read this text  using java to Jtable.

i Have used StringTokanizer And Arreaylist to ceate this. Unfotunately i couldn't done it. SO PLS HELP ME……..

So i want below result to jTable using java program.
  date     animal  total  count
11/2/2010   cat     20      3
11/3/2010   cat     9       2

  • 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-05-18T22:27:36+00:00Added an answer on May 18, 2026 at 10:27 pm

    test with : http://crysol.org/es/node/819

    or

    import java.io.BufferedReader;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.ArrayList;
    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;
    
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.event.TableModelListener;
    import javax.swing.table.TableModel;
    
    public class Reader {
    
        public Reader() {
            // TODO Auto-generated constructor stub
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JPanel panel = new JPanel();
            BufferedReader reader;
            try {
                reader = new BufferedReader(new InputStreamReader(
                                            new FileInputStream("sample.txt")));
                Map<String, Object[]> result = new LinkedHashMap<String, Object[]>();
    
                while (reader.ready()) {
                    String line = reader.readLine();
                    String[] values = line.split("\\s+");
                    String key = values[0] + "\t" + values[1];
    
                    String label = values[0];
                    String date = values[1];
                    Integer sum = 0;
                    Integer count = 0;
                    if (result.containsKey(key)) {
                        sum = (Integer) ((Object[]) result.get(key))[2];
                        count = (Integer) ((Object[]) result.get(key))[3];
                    } else {
    
                    }
                    result.put(key, new Object[]{label, date,
                            sum + Integer.parseInt(values[2]), count + 1});
                }
                ArrayList arrayList = new ArrayList(result.values());
    
                /* interate and print new output */
                /*
                 * for (String key : result.keySet()) { Integer sum =
                 * result.get(key); Integer count = result2.get(key);
                 * System.out.println(key + " " + sum + "\t" + count); }
                */
                JTable table = new JTable(new AnimalTableModel(arrayList));
                panel.add(new JScrollPane(table));
                reader.close();
                frame.setContentPane(panel);
                frame.setVisible(true);
                frame.pack();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    
        public static void main(String[] args) {
            new Reader();
        }
    
        public class AnimalTableModel implements TableModel {
            final Class[] columnClass = new Class[]{String.class, String.class,
                    Integer.class, Integer.class};
            final String[] columnName = new String[]{"Date", "Animal", "Sum",
                    "Count"};
            List values = null;
    
            public AnimalTableModel(List values) {
                this.values = values;
                // initilize values
            }
    
            @Override
            public void addTableModelListener(TableModelListener l) {
            }
    
            @Override
            public Class<?> getColumnClass(int columnIndex) {
                return columnClass[columnIndex];
            }
    
            @Override
            public int getColumnCount() {
                return columnClass.length;
            }
    
            @Override
            public String getColumnName(int columnIndex) {
                return columnName[columnIndex];
            }
    
            @Override
            public int getRowCount() {
                return values.size();
            }
    
            @Override
            public Object getValueAt(int rowIndex, int columnIndex) {
                return ((Object[]) values.get(rowIndex))[columnIndex];
            }
    
            @Override
            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return false;
            }
    
            @Override
            public void removeTableModelListener(TableModelListener l) {
            }
    
            @Override
            public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
                // TODO FOR EDITABLE DT
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey, I have some text that is formatted like this: [quote]foo text[/quote] and I
Hey everybody, this is what I have going on. I have two text files.
Hey, I have Arabic text in a txt file that I would like to
Hey I have this code right here: http://pastie.org/534470 And on line 109 I get
Hey, I have decided to reword this question (as opposed to creating a new
hey i have a counter text here and i need to know how to
I have a text file that looks similar to; section header 1: some words
Hey guys this is a followup to my previous question . I now have
Hey I'm just learning C in school and I have this idea for a
hey this is so that I should just have put some infomation into the

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.