Algorithm for sorting images by its date using Files

1.Create a file object and pass the location path of the folder in the argument.

2.Access all the files contained in the specified folder using listFiles() and it returns a file Array .Store that file Array in new file array reference.

3.Seperate the image files from the folder. check all the files ending with jpg or png extension. For this, first check the string which comes after ” . ” .

4.Use lastIndexOf() method to find the occurence of ” . ” and it returns a index. get the substring(index+1) which gives file extension. Check whether the extension is jpg/png or not. If the String is jpg /png , then do the following steps .

5.Now we will have all the images files.

6. we need to know when the image was taken. To get date, access it by lastModified() which returns a long value. Pass the long value to new created date object. The date object gives date and time in which the photo was taken.

7.Put all the image files and their corresponding dates in a TreeMap. Make image files as key and date as values. with the help of generics , specify the map consists of File and Date objects. TreeMap gives sorted order of the images with date.

8.write this sorted image files to another file .(need to discuss)

Leave a comment

Design a site like this with WordPress.com
Get started