如何使用 csv 文件中的日期和时间填充 JTable?

问题描述

这里是我一直试图转换的链接 http://www2.hawaii.edu/~takebaya/ics111/jtable_basic/jtable_basic.html

update s0_atc_code set text = regexp_replace(text,'[()*]',' ','g')

基本上我想要的是让我的 JTable 在这里显示我的 csv 文件内容

2011-12-22,12:28:51,12:28:53
2012-10-22,12:28:57,12:28:59
2010-10-22,12:29:10,12:29:12

错误信息:

package SimpleBook;

import java.time.DateTimeException;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.io.*;

public class SimpleBookList extends DateTimeException {
    private ArrayList<SimpleBook> bookList;
    public SimpleBookList() {
        super("");
        bookList = new ArrayList<SimpleBook>();
    }
    public void add(SimpleBook sb) {
        bookList.add(sb);
    }
    public void readFromCSV(String filename) {
        File file = new File(filename);
        FileReader reader = null;

        try {
            reader = new FileReader(file);
        }
        catch (FileNotFoundException e) {
            e.printstacktrace();
            System.exit(1);
        }
        BufferedReader infile = new BufferedReader(reader);
        String line = "";
        DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss");
        try {
            boolean done = false;
            while (!done) {
                line = infile.readLine();
                if (line == null) {
                    done = true;
                }
                else {
                    String[] tokens = line.split(",");
                    LocalDate date = LocalDate.parse(tokens[0],dateFormatter);
                    LocalTime clockIn = LocalTime.parse(tokens[0],timeFormatter);
                    LocalTime clockOut = LocalTime.parse(tokens[0],timeFormatter);
                    SimpleBook sb = new SimpleBook(date,clockIn,clockOut);
                    bookList.add(sb);
                }
            }
        }
        catch (Exception e) {
            e.printstacktrace();
            System.exit(1);
        }
    }
    public Object[][] convert2Data() {
        Object[][] data = new Object[bookList.size()][3];
        for (int i = 0; i < bookList.size(); i++) {
            data[i][0] = bookList.get(i).getDate();
            data[i][1] = bookList.get(i).getClockIn();
            data[i][2] = bookList.get(i).getClockOut();
        }
       return data;
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)