怎么读取一个文件的详细属性,包括创建时间,修改时间,上次访问时间,文件大小。

解决方案 »

  1.   

    File f = new File(filePath);
    f.lastModified();//上次时间
    。。
      

  2.   

    package com.diablo.utils;
    import java.io.File;
    import java.io.InputStream;
    import java.util.Date;
    import java.util.Properties;import org.apache.log4j.Logger;/**
     * 读取用户配置信息
     * @author
     *
     */
    public class Props {    Logger log = Logger.getLogger(this.getClass());    static private Props instance = null; //唯一实例    static private String propfilename = "/yj_file_conf.properties"; //配置文件    private Properties confProps = new Properties();    private long updateTime = 0;    private Props() {
            init();
        }    synchronized public static Props getInstance() {
            if (instance == null) {
                instance = new Props();
            }
            return instance;
        }    private void init() {
            InputStream is = getClass().getResourceAsStream(propfilename);
            try {
                confProps.load(is);
            } catch (Exception e) {
                log.error("不能读取配置文件,请确定conf.properties文件存在!", e);
                return;
            }
            updateTime = new Date().getTime();
        }    public String getProp(String key) {
            return (String) confProps.get(key);
        }    public void reload() {
            log.info("To reload porps");
            File file = new File(propfilename);
            long newTime = file.lastModified();
            if (newTime != updateTime) {
                log.info("reload porps start");
                InputStream is = getClass().getResourceAsStream(propfilename);
                try {
                    confProps.load(is);
                } catch (Exception e) {
                    log.error("不能读取配置文件,请确定conf.properties文件存在!", e);
                    return;
                }
                updateTime = newTime;
                log.info("reload porps end");
            }
        }}