-1

I'm trying to write a program in java which reads a file having .csv extension.

abc_{timestamp}.csv

i.e.

abc_1546473600.csv

However, I don't know what exactly the timestamp will be as the timestamp is basically the time that the data file is generated.

How can I read the file using java?

Community
  • 1
  • 1
DavidW
  • 33
  • 6
  • 1
    List the files in the parent directory, find the one you want to open, and open it? – JB Nizet Jan 04 '19 at 06:44
  • you're not asking how to read the file but rather how to identify it. Completely different question. – jwenting Jan 04 '19 at 06:46
  • be clear if you need to open all or a particular file with given timestamp. you can iterate over the list of files and find the particular file and open it. – Jabongg Jan 04 '19 at 06:47
  • What format is the timestamp? Do you want something that identifies abc_(some numbers).csv? Or you want that numbers to be timestamp – Lefteris Bab Jan 04 '19 at 07:00
  • Thank you very much for your comments. There should be only one file. But the name of file is with a timestamp which you can consider is a random number. I want to open the file but I don't know the whole name of the file name due to the number. – DavidW Jan 04 '19 at 07:15
  • Well that means in directory there is only one file, so no need to filter anything at all. If filtering is really required then FileNameFilter to choose the right files in Java is an apt choice. – Himanshu Bhardwaj Jan 04 '19 at 08:49
  • Search Stack Overflow before posting. And put more effort into drafting a very narrowly focused technical question. Stack Overflow is not a site for general guidance nor discussion. – Basil Bourque Jan 06 '19 at 07:12

1 Answers1

0

You can find the file using Regex and get the file name.

Found this link which might be of help.

How to find files that match a wildcard string in Java?