6 Replies - 297 Views - Last Post: 15 January 2018 - 09:03 AM Rate Topic: -----

#1 hm99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-January 18

Search for previous file in data format yyymmdd.

Posted 15 January 2018 - 06:52 AM

Hi

I have a directory where log txt files are logged. Each log file has the following title date format 20180114.txt, which is yyymmdd.

I want to search for data in the preceding file (date) so if the current date file is 20180114.txt, I want to search the previous day 20180113.txt, and then output the data i search for in anther text file.


How do I achieve this in java? any code examples I can follow?

thanks in advance

Is This A Good Question/Topic? 0
  • +

Replies To: Search for previous file in data format yyymmdd.

#2 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,643
  • Joined: 20-September 08

Re: Search for previous file in data format yyymmdd.

Posted 15 January 2018 - 06:55 AM

What would the output file be called?
Was This Post Helpful? 0
  • +
  • -

#3 hm99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-January 18

Re: Search for previous file in data format yyymmdd.

Posted 15 January 2018 - 07:12 AM

I could call it anything for instance, logs.txt. To make it simple, I would just copy the entire content of the existing file with date format yyyymmdd into the new one called log.txt.
Was This Post Helpful? 0
  • +
  • -

#4 g00se   User is online

  • D.I.C Lover
  • member icon

Reputation: 3623
  • View blog
  • Posts: 16,643
  • Joined: 20-September 08

Re: Search for previous file in data format yyymmdd.

Posted 15 January 2018 - 08:44 AM

Tell us more about how the search should work and what gets output
Was This Post Helpful? 0
  • +
  • -

#5 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 765
  • View blog
  • Posts: 5,762
  • Joined: 25-December 13

Re: Search for previous file in data format yyymmdd.

Posted 15 January 2018 - 08:49 AM

Quote

want to search the previous day

If you have the name of the current file (has a date), parse the date into some kind of Calendar object, subtract a day and extract the yyyy, mm and dd for the previous day's file name

This post has been edited by NormR: 15 January 2018 - 08:50 AM

Was This Post Helpful? 0
  • +
  • -

#6 hm99   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 15-January 18

Re: Search for previous file in data format yyymmdd.

Posted 15 January 2018 - 09:01 AM

Do you have any examples I can follow? I am fairly new to java
thanks
Was This Post Helpful? 0
  • +
  • -

#7 NormR   User is offline

  • D.I.C Lover
  • member icon

Reputation: 765
  • View blog
  • Posts: 5,762
  • Joined: 25-December 13

Re: Search for previous file in data format yyymmdd.

Posted 15 January 2018 - 09:03 AM

Start by reading the API doc for the Calendar and GregorianCalendar classes.
http://docs.oracle.c.../api/index.html
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1