English 中文(简体)
查阅 Java档案属性
原标题:Getting file attributes in Java

鉴于java.io.File,即.exe文档,我如何发现档案属性,例如:所创造的大小和日期,以及我如何发现可执行财产中的数据,例如:档案版本?

问题回答

值得一提的是,你在此再次提到国家食品安全扩展服务,而且直到最近(如Java SE 7)你才有机会在没有特殊身份的JNI ha窗的情况下进入这些场所。 这应当与新的NIO2档案属性交接。 其中一些属性,例如大小,是基本属性,而其他属性,如“用户”属性。

值得注意的是,介绍使用这一信息预报实例的最佳网页是。 http://www.ibm.com/developerworks/java/library/j-nio2-2/——如果你不关心其他APIC的事例,就搜寻“碎片特性”。

前言 档案室 http://docs.oracle.com/javase

If you want the version of an executable file then that is almost impossible to do in the general case as there is no standard way of versioning the files (within that file format).

The other information should be easy to get. Checkout this answer: How to discover a File s creation time with Java?

参看<代码>java.io.File。 它有如下方法:canExecute(>,length()

创建日期:http://www.jguru.com/faq/view.jsp?EID=1297118“rel=“nofollow noreferer”>。

获得档案规模的有效途径:

Simple example:

You ll need some imports...

    import java.nio.file.Path;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import java.nio.file.attribute.BasicFileAttributes;

    String fileRoot = "";
    File file = new File(fileRoot);
    if (file.isFile()) {
        Path path = Paths.get(fileRoot);
        BasicFileAttributes attr;
        try {
            attr = Files.readAttributes(path, 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());
        } catch (IOException ex) {
            Logger.getLogger(MGSiap.class.getName()).log(Level.SEVERE, null, ex);
        }
    }




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签