#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2010
    Posts
    6
    Rep Power
    0

    Unhappy Search for previous file in data format yyymmdd


    Hi

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

    I want to search for data in the preceding file (date) so if the current date file is 20180114.log, I want to search the previous day 20180113.log, 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?

    I made a start by displaying the list of the files in the directory but could do with some help to achieve the above

    public static void main(String[] args) {
    File currentDir = new File("\\\\directory Path"); // current directory
    displayDirectoryContents(currentDir);
    }

    public static void displayDirectoryContents(File dir) {
    try {
    File[] files = dir.listFiles();
    for (File file : files) {

    System.out.println(" file:" + file.getCanonicalPath());
    }

    } catch (IOException e) {
    e.printStackTrace();
    }
    }


    thanks in advance
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,737
    Rep Power
    352

IMN logo majestic logo threadwatch logo seochat tools logo