Programming Tips - How do I write to the SD card?

Date: 2016aug22 OS: Android Keywords: secure digital Q. How do I write to the SD card? A. Like this:
// Helper function to get the path String getExternalStorage() { return Environment.getExternalStorageDirectory().getAbsolutePath(); } <!-- Add this to your manifest --> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> void writeOnSdcard() { String dir = getExternalStorage() + "/something-unique"; File fDir = new File(dir); if (!fDir.exists()) { fDir.mkdirs(); } String file = dir + "/myfile.txt"; // Now its just regular Java I/O PrintWriter writer = new PrintWriter(file, "UTF-8"); writer.println("Hello"); writer.println("SD Card"); writer.close() }