Created
August 13, 2013 02:45
-
-
Save tomoyamkung/6217413 to your computer and use it in GitHub Desktop.
[Java]FileUtils#iterateFiles を使ったファイルフィルタのスニペット。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.tomoyamkung.commons.io.fileutils; | |
import static org.hamcrest.CoreMatchers.*; | |
import static org.junit.Assert.*; | |
import java.io.File; | |
import java.util.Iterator; | |
import org.apache.commons.io.FileUtils; | |
import org.junit.Test; | |
public class FileUtilsTest { | |
@Test | |
public void 拡張子がtxtのFileオブジェクトを取得する() throws Exception { | |
// Setup | |
File directory = new File("testdata/commons_io_fileutils/fileutilstest"); | |
String[] extensions = {"txt"}; | |
boolean recursive = false; | |
// Exercise | |
Iterator<File> actual = FileUtils.iterateFiles(directory, extensions, recursive); | |
// Verify | |
assertThat(actual.hasNext(), is(true)); | |
File next = actual.next(); | |
assertThat(next.getName(), is("hoge1.txt")); | |
assertThat(actual.hasNext(), is(true)); | |
next = actual.next(); | |
assertThat(next.getName(), is("hoge2.txt")); | |
assertThat(actual.hasNext(), is(false)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
テストデータとして、"testdata/commons_io_fileutils/fileutilstest" ディレクトリを作成し、そこに次のファイルを用意する。