Skip to content

Instantly share code, notes, and snippets.

@atengberg
Created December 15, 2014 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save atengberg/e1d3e4c55cb53505fe66 to your computer and use it in GitHub Desktop.
Save atengberg/e1d3e4c55cb53505fe66 to your computer and use it in GitHub Desktop.
copy file from raw resource
private void copyFile(String fromPath, String fileName, int file) {
InputStream in = null;
OutputStream out = null;
try {
in = getResources().openRawResource(file);
out = new FileOutputStream(new File(fromPath, fileName));
byte[] buffer = new byte[1024];
int read;
while ((read = in.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
} catch (FileNotFoundException oops) {
} catch (IOException ignore) {
}
finally {
try {
if (in != null) { in.close(); }
if (out != null) { out.flush(); out.close(); }
} catch (IOException ignore) { }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment