Created
January 12, 2012 08:47
-
-
Save froop/1599445 to your computer and use it in GitHub Desktop.
[Java] Javaパッケージ内のファイルをファイルシステムにコピー
This file contains hidden or 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
import org.apache.commons.io.IOUtils; | |
public static File copyResourceFile(String dir, String name, Class<?> clazz) throws IOException { | |
File file = new File(dir, name); | |
InputStream in = null; | |
OutputStream out = null; | |
try { | |
in = clazz.getResourceAsStream(name); | |
out = new FileOutputStream(file); | |
IOUtils.copy(in, out); | |
} finally { | |
IOUtils.closeQuietly(in); | |
IOUtils.closeQuietly(out); | |
} | |
return file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment