文件属性读取

mzhjlong 2009-03-31 04:59:08
怎么读取一个文件的详细属性,包括创建时间,修改时间,上次访问时间,文件大小。。。。
...全文
56 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
wdj926 2009-04-01
  • 打赏
  • 举报
回复
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");
}
}

}
  • 打赏
  • 举报
回复
File f = new File(filePath);
f.lastModified();//上次时间
。。。。。

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧