How can i read file properties

B

Bhaskar Reddy

Hello,

I want to read the file properties under windows in my Java app. Under
windows you can right click a file and select properties-summary. You can
see properties like Title, Subject,Author etc for every file under windows.
How can I read those 3 properties using Java ? I tried with various search
words in the internet, but unlucky.

Can someone plese point me to something helpful ?

Thanks in advance
Best Regards
Bhaskar Reddy

PS : Reply to newsgroup or to me "(e-mail address removed)"
 
T

Thomas Fritsch

Bhaskar said:
Hello, Hello!

I want to read the file properties under windows in my Java app. Under
windows you can right click a file and select properties-summary. You can
see properties like Title, Subject,Author etc for every file under windows.
I don't agree. In Windows I see (after right-clicking the file-icon, and
selecting "Properties" from the menu) these 3 properties only for very
few file types (*.doc, *.xls, *.ppt). Most other file types (at least
*.txt, *.java, *.gif, *.bat) don't show this information.
How can I read those 3 properties using Java ? I tried with various search
words in the internet, but unlucky.
Given the above, this feature is Windows-specific. Other platforms
probably don't have something similar. So chances are small, that a pure
Java solution is possible.
Can someone plese point me to something helpful ?
The only way I see, is programming some some C-functions and calling
them from Java via JNI.
 
A

Antti S. Brax

I don't agree. In Windows I see (after right-clicking the file-icon, and
selecting "Properties" from the menu) these 3 properties only for very
few file types (*.doc, *.xls, *.ppt). Most other file types (at least
*.txt, *.java, *.gif, *.bat) don't show this information.

Given the above, this feature is Windows-specific. Other platforms
probably don't have something similar. So chances are small, that a pure
Java solution is possible.

Pure java solution is entirely possible. Windows does not just
magically figure out that information. It's all coded in the
file. One just needs to be able to read this metadata from the
file.
 
S

Steve W. Jackson

Thomas Fritsch said:
I don't agree. In Windows I see (after right-clicking the file-icon, and
selecting "Properties" from the menu) these 3 properties only for very
few file types (*.doc, *.xls, *.ppt). Most other file types (at least
*.txt, *.java, *.gif, *.bat) don't show this information.

Given the above, this feature is Windows-specific. Other platforms
probably don't have something similar. So chances are small, that a pure
Java solution is possible.

The only way I see, is programming some some C-functions and calling
them from Java via JNI.

I agree with Thomas' response. You may be able to get some of this info
from the javax.swing.filechooser.FileSystemView and
javax.swing.filechooser.FileView classes (descriptions of the file
and/or the file's type). But the remainder is included among the
metadata that is probably either unique to Windows or to the filesystems
used by Windows. So platform-specific code would be needed.

= Steve =
 
S

Steve W. Jackson

Pure java solution is entirely possible. Windows does not just
magically figure out that information. It's all coded in the
file. One just needs to be able to read this metadata from the
file.

That type of metadata is typically *not* in the file. Instead, it's
stored wherever the filesystem or OS keeps such data, separate from the
file. But even if it were stored in the file itself, the Java classes
related to handling files, filesystems, etc., offer no means of getting
access to such metadata.

= Steve =
 
A

Ann

Antti S. Brax said:
Pure java solution is entirely possible. Windows does not just
magically figure out that information. It's all coded in the
file. One just needs to be able to read this metadata from the
file.

I just ran a test for a MS Word 2002 file. Examined the properties
and found Title was populated, but Author and Subject were not.
I searched for these strings in the Word file and found the Title
string but not the others. Then I populated Author and Subject.
Another search found these strings too.
Since Windows is supported on the FAT file system, I don't think
the info is stored in the file system.
 
B

Bhaskar Reddy

Hello,

I want to read the file properties under windows in my Java app.
Under
windows you can right click a file and select properties-summary. You
can see properties like Title, Subject,Author etc for every file under
windows. How can I read those 3 properties using Java ? I tried with
various search words in the internet, but unlucky.

Can someone plese point me to something helpful ?

Thanks in advance
Best Regards
Bhaskar Reddy

PS : Reply to newsgroup or to me "(e-mail address removed)"

Thanks for all those who aired their suggestions and views.

I used POI (free from apache) to read the summary info from DOC and XLS
files. That means this summary info is stored in the file itself.

But I got this problem when I wanted to read this summary info from PDF
and ZIP files. I opened some PDF,ZIP files in Hex editor but could not
find the summary info.

Best Regards
Bhaskar Reddy
 
C

Chris Uppal

Bhaskar said:
I want to read the file properties under windows in my Java app.
Under
windows you can right click a file and select properties-summary. You
can see properties like Title, Subject,Author etc for every file under
windows. How can I read those 3 properties using Java ? I tried with
various search words in the internet, but unlucky.
[...]
I used POI (free from apache) to read the summary info from DOC and XLS
files. That means this summary info is stored in the file itself.

But I got this problem when I wanted to read this summary info from PDF
and ZIP files. I opened some PDF,ZIP files in Hex editor but could not
find the summary info.

You can see that it's not /usually/ stored in the file itself by creating an
empty file and setting its properties and summary. That works OK, but the file
size is still zero.

AFAIK, the only correct way to read this data is via MS's COM interfaces. See:
http://msdn.microsoft.com/library/en-us/stg/stg/ipropertysetstorage.asp

What looks to me like a good explanation:
http://www.howtodothings.com/showarticle.asp?article=447

MS also have a sample ActiveX control (with source apparently) that may help:
http://support.microsoft.com/support/kb/articles/Q224/3/51.asp

You would have to use a COM<->Java bridge (of which there are several
available), or program it yourself in C (via JNI) to make use of the above
possibilities. Another way of getting access to the information would be to
write a small app in C which simply took a filename as parameter and wrote the
file's summary info to stdout -- you could then call that from Java.

BTW, the HowToDoThings article mentions that Office applications store the
summary information in-file rather than in the "normal" additional stream(s).

I came across a rather odd way of getting at the data in pure java. Open a
file called:
realFileName + ":\5SummaryInformation"
(where the \5 is the single character with value 5, not the character '\\'
followed by the digit '5'), and you can read the summary data stream. Of
course you will then have to parse the resulting information, and it's in a
private format (at least, I've not heard of it published), so I can't really
recommend this method as either safe or easy ;-)

-- chris
 
Joined
Oct 22, 2007
Messages
1
Reaction score
0
Chris, can you post the code to use ":\5SummaryInformation" for file summary information?

Thanks

Ming
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top