Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the metadata of a file

Tags:

It is possible to know the metadata of a file in java? and if it is, How to get the metadata of a file in java?

like image 619
josemm1790 Avatar asked May 30 '12 20:05

josemm1790


2 Answers

There is a basic set of metadata that you can get from a file.

Path file = ...;
BasicFileAttributes attr = Files.readAttributes(file, BasicFileAttributes.class);

System.out.println("creationTime: " + attr.creationTime());
System.out.println("lastAccessTime: " + attr.lastAccessTime());
System.out.println("lastModifiedTime: " + attr.lastModifiedTime());

System.out.println("isDirectory: " + attr.isDirectory());
System.out.println("isOther: " + attr.isOther());
System.out.println("isRegularFile: " + attr.isRegularFile());
System.out.println("isSymbolicLink: " + attr.isSymbolicLink());
System.out.println("size: " + attr.size());

Some things are platform dependent and may throw exceptions or return unexpected results.

You can read more at Managing Metadata (File and File Store Attributes).

like image 104
Beau Grantham Avatar answered Sep 30 '22 02:09

Beau Grantham


FITS is a command line app that bundles many tools that can identify and characterize files (extract metadata). It also has a java API

  • http://code.google.com/p/fits/
  • http://code.google.com/p/fits/wiki/developer_documentation

Also there are numerous identification and characterization tools that can do similar tasks. Apache Tika, Pronom Droid, Jhove, etc.

like image 43
peshkira Avatar answered Sep 30 '22 04:09

peshkira