2010年5月2日日曜日

groovyとApache Commons VFSでRAMファイルシステム上のファイルを列挙する

groovyとApache Commons VFSでRAMファイルシステム上のファイルを列挙するには、以下のコードを実行します。

import org.apache.commons.vfs.*

fsm = VFS.getManager()

// RAM file systemにファイルをコピー
fsm.resolveFile( "ram://test.txt").copyFrom(
fsm.resolveFile("C:\\share\\commons-vfs\\test.txt"),
new AllFileSelector())

fsm.resolveFile( "ram://test2.txt").copyFrom(
fsm.resolveFile("C:\\share\\commons-vfs\\test2.txt"),
new AllFileSelector())

fsm.resolveFile( "ram://test3.txt").copyFrom(
fsm.resolveFile("C:\\share\\commons-vfs\\test3.txt"),
new AllFileSelector())

// RAM file systemのファイルを列挙
files = fsm.resolveFile("ram:///").getChildren()
for(file in files){
println file.getName().getBaseName()
}


動作環境
groovy 1.7.1, JDK6 Update19, apache commons vfs 1.0, apache commons logging 1.1.1

0 件のコメント:

コメントを投稿