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