通常来讲,如今的相机进行拍照都会带上相关的基本信息,包括拍照时间,大小等,咱们能够经过下面的代码获取照片的相关信息。复制代码
public static void main(String[] args) {
File jpegFile = new File("E:\\20190425143833.jpg");
Long fileTime = jpegFile.lastModified();
System.out.println(fileTime);
Metadata metadata;
try {
metadata = JpegMetadataReader.readMetadata(jpegFile);
Iterator<Directory> it = metadata.getDirectories().iterator();
while (it.hasNext()) {
Directory exif = it.next();
Iterator<Tag> tags = exif.getTags().iterator();
while (tags.hasNext()) {
Tag tag = (Tag) tags.next();
System.out.println(tag);
}
}
} catch (JpegProcessingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
复制代码
对于结果输出我这里就再也不进行说明了,打印出来后基本上都能认出来相关属性,这个从属性名上来讲就很好辨认的bash