Rename a photo Based on the EXIF time

Source: Internet
Author: User
1   Import  Java. Io. file;  2    Import  Java. util. iterator;  3    4    Import  Com.drew.imaging.jpeg. jpegmetadatareader;  5    Import  Com. Drew. Metadata. Directory;  6    Import  Com. Drew. Metadata. metadata; 7    Import  Com. Drew. Metadata. Tag;  8    Import  Com. Drew. Metadata. EXIF. exifdirectory;  9    10    Public   Class  Renamepic {  11        Public   Static   Void  Main (string [] ARGs ){ 12            Try  {  13 String dir = "D:/uri /" ;  14 File directory = New  File (DIR );  15 File [] files = Directory. listfiles ();  16                For ( Int I = 0; I <files. length; I ++ ){ 17 File Extension file = New File (DIR + Files [I]. getname ());  18 Metadata metadata = Using metadatareader. readmetadata (using file );  19 Directory EXIF = metadata. getdirectory (exifdirectory. Class  );  20 Iterator tags = EXIF. gettagiterator ();  21                    While (Tags. hasnext ()){  22 Tag tag = (TAG) tags. Next ();  23                        If (Tag. gettagname (). Equals ("date/time original" )){  24 String time = tag. getdescription (). replaceall (":","" )  25 . Replaceall ("","_" );  26 File refile = New File (DIR + "IMG _" + time + ". jpg" );  27   Using file. renameto (refile );  28   }  29   }  30   }  31 } Catch  (Exception e ){  32   E. printstacktrace (); 33   }  34   }  35   }  36   

JAR file: metadata-extractor-2.3.1.jar

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.