﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-夸父追日-随笔分类-class</title><link>http://www.blogjava.net/quaff/category/5783.html</link><description>飞蛾扑火</description><language>zh-cn</language><lastBuildDate>Fri, 02 Mar 2007 06:53:01 GMT</lastBuildDate><pubDate>Fri, 02 Mar 2007 06:53:01 GMT</pubDate><ttl>60</ttl><item><title>用jarkata的commons-VFS监视文件夹的变化</title><link>http://www.blogjava.net/quaff/archive/2006/03/02/33229.html</link><dc:creator>quaff</dc:creator><author>quaff</author><pubDate>Thu, 02 Mar 2006 07:48:00 GMT</pubDate><guid>http://www.blogjava.net/quaff/archive/2006/03/02/33229.html</guid><wfw:comment>http://www.blogjava.net/quaff/comments/33229.html</wfw:comment><comments>http://www.blogjava.net/quaff/archive/2006/03/02/33229.html#Feedback</comments><slash:comments>5</slash:comments><wfw:commentRss>http://www.blogjava.net/quaff/comments/commentRss/33229.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/quaff/services/trackbacks/33229.html</trackback:ping><description><![CDATA[<DIV style="BORDER-RIGHT: #cccccc 1px solid; PADDING-RIGHT: 5px; BORDER-TOP: #cccccc 1px solid; PADDING-LEFT: 4px; FONT-SIZE: 13px; PADDING-BOTTOM: 4px; BORDER-LEFT: #cccccc 1px solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: #cccccc 1px solid; BACKGROUND-COLOR: #eeeeee"><SPAN style="COLOR: #000000">FileSystemManager&nbsp;fsManager&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;&nbsp;<BR>FileObject&nbsp;listendir&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">null</SPAN><SPAN style="COLOR: #000000">;&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">try</SPAN><SPAN style="COLOR: #000000">&nbsp;{&nbsp;<BR>fsManager&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;VFS.getManager();&nbsp;<BR>listendir&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;fsManager.resolveFile(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;File(&nbsp;<BR></SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">./classes/</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">).getAbsolutePath());&nbsp;<BR>}&nbsp;</SPAN><SPAN style="COLOR: #0000ff">catch</SPAN><SPAN style="COLOR: #000000">&nbsp;(FileSystemException&nbsp;e)&nbsp;{&nbsp;<BR>log.error(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">监视文件夹出错了</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">,&nbsp;e);&nbsp;<BR>e.printStackTrace();&nbsp;<BR>}&nbsp;<BR>DefaultFileMonitor&nbsp;fm&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;DefaultFileMonitor(</SPAN><SPAN style="COLOR: #0000ff">new</SPAN><SPAN style="COLOR: #000000">&nbsp;FileListener()&nbsp;{&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;fileCreated(FileChangeEvent&nbsp;event)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception&nbsp;{&nbsp;<BR>monitor(event);&nbsp;<BR>}&nbsp;<BR><BR></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;fileDeleted(FileChangeEvent&nbsp;event)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception&nbsp;{&nbsp;<BR>monitor(event);&nbsp;<BR>}&nbsp;<BR><BR></SPAN><SPAN style="COLOR: #0000ff">public</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;fileChanged(FileChangeEvent&nbsp;event)&nbsp;</SPAN><SPAN style="COLOR: #0000ff">throws</SPAN><SPAN style="COLOR: #000000">&nbsp;Exception&nbsp;{&nbsp;<BR>monitor(event);&nbsp;<BR>}&nbsp;<BR><BR></SPAN><SPAN style="COLOR: #0000ff">private</SPAN><SPAN style="COLOR: #000000">&nbsp;</SPAN><SPAN style="COLOR: #0000ff">void</SPAN><SPAN style="COLOR: #000000">&nbsp;monitor(FileChangeEvent&nbsp;event)&nbsp;{&nbsp;<BR>FileObject&nbsp;fileObject&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;event.getFile();&nbsp;<BR>FileName&nbsp;fileName&nbsp;</SPAN><SPAN style="COLOR: #000000">=</SPAN><SPAN style="COLOR: #000000">&nbsp;fileObject.getName();&nbsp;<BR></SPAN><SPAN style="COLOR: #0000ff">if</SPAN><SPAN style="COLOR: #000000">&nbsp;(fileName.getBaseName().endsWith(</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">.class</SPAN><SPAN style="COLOR: #000000">"</SPAN><SPAN style="COLOR: #000000">))&nbsp;{&nbsp;<BR>reload();&nbsp;<BR>}&nbsp;<BR>}&nbsp;<BR>});&nbsp;<BR>fm.setRecursive(</SPAN><SPAN style="COLOR: #0000ff">true</SPAN><SPAN style="COLOR: #000000">);&nbsp;<BR>fm.addFile(listendir);&nbsp;<BR>fm.start();<BR><BR></SPAN></DIV><img src ="http://www.blogjava.net/quaff/aggbug/33229.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/quaff/" target="_blank">quaff</a> 2006-03-02 15:48 <a href="http://www.blogjava.net/quaff/archive/2006/03/02/33229.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>