Created
December 15, 2014 10:19
-
-
Save atengberg/e1d3e4c55cb53505fe66 to your computer and use it in GitHub Desktop.
copy file from raw resource
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
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