Skip to content

Instantly share code, notes, and snippets.

@froop
Created January 12, 2012 08:47
Show Gist options
  • Save froop/1599445 to your computer and use it in GitHub Desktop.
Save froop/1599445 to your computer and use it in GitHub Desktop.
[Java] Javaパッケージ内のファイルをファイルシステムにコピー
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