Created
March 8, 2011 04:56
-
-
Save nickfox/859860 to your computer and use it in GitHub Desktop.
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 writeToSDCard() { | |
try { | |
File root = Environment.getExternalStorageDirectory(); | |
if (root.canWrite()){ | |
InputStream from = myContext.getResources().openRawResource(rID); | |
File dir = new java.io.File (root, "pdf"); | |
dir.mkdir(); | |
File writeTo = new File(root, "pdf/" + attachmentName); | |
FileOutputStream to = new FileOutputStream(writeTo); | |
byte[] buffer = new byte[4096]; | |
int bytesRead; | |
while ((bytesRead = from.read(buffer)) != -1) | |
to.write(buffer, 0, bytesRead); // write | |
to.close(); | |
from.close(); | |
} else { | |
Log.d(TAG, "Unable to access SD card."); | |
} | |
} catch (Exception e) { | |
Log.d(TAG, "writeToSDCard: " + e.getMessage()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment