How to get the last modified date and time of a File or Directory in Java? Example Tutorial

Sometimes before processing a file, you want to check its last modified date to avoid processing an old file. Though some programmers prefer to attach the date in the file name itself, I don't find it a cleaner approach. For example, suppose you are downloading closing prices of stocks and processing them at the start of the day, and loading them into the database. In order to accidentally process an old file, you can check the last modified date before processing and if it's in the acceptable range, you can process the file. You can get the last modified date of a file in Java by using java.io.File class. 

تعليقات

المشاركات الشائعة من هذه المدونة

Why use Underscore in Numbers from Java? Underscore in Numeric Literals Example

3 ways to convert String to Boolean in Java? Examples

Coursera's TensorFlow: Advanced Techniques Specialization Review [2022]