Duffblog
前進一步,看看,需要前進更大一步才可以。
BlogJava
::
首頁
::
新隨筆
::
聯系
::
聚合
::
管理
::
5 隨筆 :: 53 文章 :: 5 評論 :: 0 Trackbacks
<
2025年7月
>
日
一
二
三
四
五
六
29
30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
常用鏈接
我的隨筆
我的評論
我的參與
最新評論
留言簿
(2)
給我留言
查看公開留言
查看私人留言
隨筆檔案
2006年9月 (2)
2006年5月 (2)
2006年3月 (1)
文章分類
J2EE
(rss)
Java(17)
(rss)
Tomcat
(rss)
山路漫步(8)
(rss)
開源技術(2)
(rss)
技術文摘(18)
(rss)
文章檔案
2006年12月 (8)
2006年11月 (2)
2006年10月 (7)
2006年9月 (4)
2006年8月 (8)
2006年7月 (2)
2006年6月 (6)
2006年5月 (6)
2006年4月 (10)
網站
http://blog.lupaworld.com/blog
JavaWorld TW
(rss)
臺灣不錯的Java方面的論壇.
最新評論
1.?re: 結合Spring2.0和ActiveMQ進行異步消息調用(轉)[未登錄]
有個問題不明白,就是是否不用啟動監聽容器?那么接收端不用啟動就能獲取到消息了?
--leven
2.?re: JVM的內存管理機制 java.lang.OutOfMemoryError: PermGen space [未登錄]
不對啊,我個還是不行啊,我用了myeclipse,使用了hibernate,struts
--liu
3.?re: (轉)voa的學習技巧和經驗
well written!it's better to wrote in English.That is professional.
--蔣文明
4.?re: 如何正確地應用Runtime類調用程序
評論內容較長,點擊標題查看
--pc
5.?re: Spring的一些參考。(http://www.aygfsteel.com/calvin/category/2823.html)
評論內容較長,點擊標題查看
--pc
閱讀排行榜
1.?Spring的一些參考。(http://www.aygfsteel.com/calvin/category/2823.html)(350)
2.?百名專家推薦適合中國人10大減壓方法(轉)(283)
3.?感嘆!!!(257)
4.?隨便寫寫關于Object(231)
5.?晃悠~~晃悠~~(192)
評論排行榜
1.?Spring的一些參考。(http://www.aygfsteel.com/calvin/category/2823.html)(1)
2.?晃悠~~晃悠~~(0)
3.?百名專家推薦適合中國人10大減壓方法(轉)(0)
4.?感嘆!!!(0)
5.?隨便寫寫關于Object(0)
Java讀取File的問題
我想要讀取某一個路徑下,文件最后修改的時間大于我給定的所有的文件.
比如是E:\file
我想要等到一部分的file,即是文件最后修改的時間大于我給定的
我目前的做法是:
查看所有的File,一一比對,得到我想要的File
//read path
Vector needReadFile = new Vector();
Date fileDate = new Date();
File[] files = new File(readFilePath).listFiles();
if (files == null) {
continue;
}
for (int x = 0; x < files.length; x++) {
File tempFile = files[x];
Date fileDate = new Date(tempFile.
lastModified());
if (fileDate.compare(lastModifyDate) == 1 ) {
needReadFile.add(readFilePath + File.separator +
tempFile.getName());
}
} //end for(int i = 0 ; i< files.length ; i++)
雖然這樣做是可以達到,當我的File很多的時候,效率很差了
效率好一點的方法:
看看listFiles()和listFiles(FileFilter filter) 的源代碼
public File[] listFiles() {
String[] ss = list();
if (ss == null) return null;
int n = ss.length;
File[] fs = new File[n];
for (int i = 0; i < n; i++) {
fs[i] = new File(this.path, ss[i]);
}
return fs;
}
public File[] listFiles(FileFilter filter) {
String ss[] = list();
if (ss == null) return null;
ArrayList v = new ArrayList();
for (int i = 0 ; i < ss.length ; i++) {
File f = new File(this.path, ss[i]);
if ((filter == null) || filter.accept(f)) {
v.add(f);
}
}
return (File[])(v.toArray(new File[0]));
}
采用第二個方法以后,只需要遍歷一遍,而且代碼更清晰,
采用第一個方法,你取得列表以后還需要遍歷一遍過濾掉不符合條件的.
File[] files = new File(readFilePath).listFiles(new FileFilter(){
public boolean accept(File pathname){
//.判斷修改日期,符合條件返回true;否則false;
}});
這里采用匿名類,實現一個FileFilter,你要修改過濾的邏輯,只需要修改accept()方法就是了,當然,你也可以專門寫一個類比如
class FileModifyDateFilter implements FileFilter{
private Date baseDate = null;
public FileModifyDateFilter(Date d) {
baseDate = d;
}
public boolean accept(File f) {
if (baseDate == null)
return true;
if (f.lastModified() > baseDate.getTime())
return true;
return false;
}
}
原文來自:
http://www.jdon.com/jive/thread.jsp?forum=16&thread=22478&message=13169392
posted on 2006-04-04 21:17
追球者
閱讀(849)
評論(0)
編輯
收藏
所屬分類:
Java
新用戶注冊
刷新評論列表
只有注冊用戶
登錄
后才能發表評論。
網站導航:
博客園
IT新聞
Chat2DB
C++博客
博問
管理
相關文章:
算術表達式的計算(轉)
算術表達式(轉)
Java正則表達式詳解(轉)-----入門知識。
Java 虛禮機的一些配置。
Spring用JDBC 調用ORACLE存儲過程的結果集
Java AWT Clipboard(Java剪貼板)的用法。
咖啡,還是淡些好
JAVA內存泄漏——內存泄漏原因和內存泄漏檢測工具(zt)
Apache commons (轉)
hibernate hql(轉)
Powered by:
BlogJava
Copyright © 追球者
主站蜘蛛池模板:
周至县
|
独山县
|
洛川县
|
宁津县
|
仲巴县
|
温州市
|
金塔县
|
和顺县
|
堆龙德庆县
|
洪江市
|
嘉善县
|
祥云县
|
出国
|
河南省
|
信丰县
|
昭通市
|
崇礼县
|
吴桥县
|
阳原县
|
宁波市
|
濉溪县
|
鄂州市
|
湖南省
|
滦平县
|
麻江县
|
潮安县
|
鸡东县
|
台南市
|
龙胜
|
湟源县
|
民县
|
桐城市
|
洛南县
|
荆门市
|
农安县
|
延川县
|
韩城市
|
青海省
|
康保县
|
中西区
|
融水
|