[java]代码库
import java.io.File;
import java.util.Iterator;
import com.drew.imaging.jpeg.JpegMetadataReader;
import com.drew.metadata.Directory;
import com.drew.metadata.Metadata;
import com.drew.metadata.Tag;
import com.drew.metadata.exif.ExifDirectory;
public class RenamePic {
public static void main (String[] args) {
try {
String dir = "C:/pic/";
File directory = new File (dir);
File[] files = directory.listFiles();
for (int i = 0; i < files.length; i++) {
File jpegFile = new File (dir + files[i].getName() );
Metadata metadata = JpegMetadataReader.readMetadata (jpegFile);
Directory exif = metadata.getDirectory (ExifDirectory.class);
Iterator tags = exif.getTagIterator();
while (tags.hasNext() ) {
Tag tag = (Tag) tags.next();
if (tag.getTagName().equals ("Date/Time Original") ) {
String time = tag.getDescription().replaceAll (":", "")
.replaceAll (" ", "_");
File reFile = new File (dir + "IMG_" + time + ".jpg");
jpegFile.renameTo (reFile);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
[源代码打包下载]