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;
}
答案 0 :(得分:2)
尝试一下。
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());
}
}