Created
July 18, 2014 11:34
-
-
Save anonymous/dfec2d367b2de0d130fd to your computer and use it in GitHub Desktop.
How keep your files in assets. The following code may help you to copy contents from assets directory to SD Card.
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
public static void copyFile(Activity c, String filename) | |
{ | |
AssetManager assetManager = c.getAssets(); | |
InputStream in = null; | |
OutputStream out = null; | |
try | |
{ | |
in = assetManager.open(filename); | |
String newFileName = sdcardpath/filename; | |
out = new FileOutputStream(newFileName); | |
byte[] buffer = new byte[1024]; | |
int read; | |
while ((read = in.read(buffer)) != -1) | |
{ | |
out.write(buffer, 0, read); | |
} | |
in.close(); | |
in = null; | |
out.flush(); | |
out.close(); | |
out = null; | |
} catch (Exception e) { | |
Utility.printLog("tag", e.getMessage()); | |
}finally{ | |
if(in!=null){ | |
try { | |
in.close(); | |
} catch (IOException e) { | |
printLog(TAG, "Exception while closing input stream",e); | |
} | |
} | |
if(out!=null){ | |
try { | |
out.close(); | |
} catch (IOException e) { | |
printLog(TAG, "Exception while closing output stream",e); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment