文件属性读取 怎么读取一个文件的详细属性,包括创建时间,修改时间,上次访问时间,文件大小。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 File f = new File(filePath);f.lastModified();//上次时间。。 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"); } }} 使用多线程实现打印出ABCABC10次循环 java clone 深度问题(final 对象clone) 如何实现删除前请用户确认的功能! 关于打包成jar的小问题 关于JAVA String存储问题 大哥,帮我看看这个方法 那位大虾解决一下新手的困惑? 我用Socket做通信,一方是简体中文环境,一方可能是繁体中文环境,如果是繁体的都是乱码,如何解决? 不能置换“\"字符? 为什么Forte IDE中的中文都是乱码? eclipse中通过ant task 去调用java类 java jdbc操作mysql数据库
f.lastModified();//上次时间
。。
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");
}
}}