|
-
January 16th, 2018, 10:37 AM
#1
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
Code:
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
Last edited by 2kaud; January 16th, 2018 at 10:46 AM.
Reason: Added code tags
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|