Last active
April 29, 2016 03:15
-
-
Save moneeb777/757d7238fdb5224546b2530cc0837dc2 to your computer and use it in GitHub Desktop.
Android I/O- write file to storage
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
// find the root of the external storage | |
File root = android.os.Environment.getExternalStorageDirectory(); | |
myRootFolder.append("\nExternal file system root: " + root); | |
//make a new directory | |
File dir = new File (root.getAbsolutePath() + "/testDownload"); | |
dir.mkdirs(); | |
File file = new File(dir, "testData.txt"); | |
try { | |
FileOutputStream f = new FileOutputStream(file); | |
PrintWriter pw = new PrintWriter(f); | |
pw.println("Hello World"); | |
pw.flush(); | |
pw.close(); | |
f.close(); //An error occurs if you do not implement a catch for this expression | |
} catch (Exception e) { | |
e.printStackTrace(); | |
Log.i(LOG_TAG, "File not found. Probably a permissions issue"); | |
} | |
myRootFolder.append("\n\nFile written to" + file); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment