【问题标题】:How to read a text file with timestamp? in Java如何读取带有时间戳的文本文件?在爪哇
【发布时间】:2019-07-19 14:29:39
【问题描述】:

Asterisk 在 java 中可以工作吗?我想读取带有时间戳的文件。 taxonomy_timestamp.txt 但它不起作用。

    String fileName = "20190215/"+"taxonomy_*.txt";
        try (BufferedReader reader = new BufferedReader(new FileReader(fileName))) {

            String line;

            while ((line = reader.readLine()) != null) {
                if(line.contains(":")) {
                    String[] segmentData = line.split(":");
                    String keyword = segmentData[0];
                    String name = segmentData[1];
                    segmentList.add(new ExternalSegmentDownloader.ExternalSegmentKey(keyword, name));
                }
            }
        }catch(IOException e){
            log.info("File not found.",e);
        }
        return segmentList;
    }

【问题讨论】:

标签: java file


【解决方案1】:

试试这个。

public static void main(String[] args) throws IOException {
    File directory = new File(".");

    File[] files = directory.listFiles();
    System.out.println("All files and directories:");
    displayFiles(files);

    String pattern =  "20190215/"+"taxonomy_[*].txt";
    System.out.println("\nFiles that match regular expression: " + pattern);
    FileFilter filter = new RegexFileFilter(pattern);
    files = directory.listFiles(filter);
    displayFiles(files);

}

public static void displayFiles(File[] files) {
    for (File file : files) {
        System.out.println(file.getName());
    }
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    相关资源
    最近更新 更多