0

I have files such:

buy.txt.xxx
buy.txt.yyy
buy.txt.zzz ...

Where xxx, yyy and zzz are unix timestamp I want to allow user to search in limited date: For example the user will enter these three variables(startDate,endDate,wordToSearch):

Text Field1: 2017-05-01
Text Field2: 2017-05-05
Text Field3: wordToSearch

And the java app will convert startDate and endDate entered by user to Unix timestamp and loop through the files to get the lines contain the wordToSearch. How I can implemented such this in java

userY
  • 9
  • 3

1 Answers1

0

If I understood your question correctly you can create file name like this:

    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date searchDate = dateFormat.parse("2017-05-01");
    long timestamp = searchDate.getTime();
    String filename = "buy.txt."+timestamp;

After that search through filename like you did before.

Dipesh
  • 305
  • 4
  • 13
  • In that case you can read all the filenames within a folder using https://stackoverflow.com/a/1846349/1967285 and from file name get the timestamp part using split method. Then check if that timestamp is within given range or not. If yes then open the file and start searching else move to another file – Dipesh Jul 12 '17 at 15:06
  • I will try that. – userY Jul 12 '17 at 18:00