在Java中获取文件属性 [英] Getting file attributes in Java

查看:191
本文介绍了在Java中获取文件属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出代表 .exe 文件的 java.io.File ,如何发现文件属性 - 例如:创建的大小和日期,以及如何发现可执行属性中的数据 - 例如:file version?

Given a java.io.File that represents a .exe file, how can I discover the file attributes - for example: size and date created, and how could I discover the data in the executable properties - for example: file version?

推荐答案

p>据推测,这里指的是NTFS扩展属性,它只是最近(从Java SE 7),你已经能够得到这些没有某种Windows特定的JNI黑客。这应该可以用新的NIO2文件属性接口。这些属性中的一些(例如大小)是基本属性,而诸如版本的其他属性是用户属性。

Presumably you're referring to NTFS Extended Attributes here, and it's only recently (as of Java SE 7) that you've been able to get at these without some kind of windows specific JNI hackery. This should be doable with the new NIO2 file attributes interface. Some of these attributes, such as size, are basic attributes, while others such as version are "user" attributes.

可能是最好的网页提供了解释此API使用的示例,网址为http://www.ibm.com/developerworks/java/library/j-nio2-2/ - 如果您不感兴趣,请搜索文件属性在其他API的示例中。

Probably the best page with examples that explains the use of this API is at http://www.ibm.com/developerworks/java/library/j-nio2-2/ -- search down for "File attributes" if you're not interested in the examples of the other APIs.

这篇关于在Java中获取文件属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆