if (Environment.MEDIA_MOUNTED.equals(state)) { // We can read and write the media mExternalStorageAvailable = mExternalStorageWriteable = true;} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) { // We can only read the media mExternalStorageAvailable = true; mExternalStorageWriteable = false;} else { // Something else is wrong. It may be one of many other states, but all we need // to know is we can neither read nor write mExternalStorageAvailable = mExternalStorageWriteable = false;}

File sdcard = Environment.getExternalStorageDirectory();// to this path add a new directory pathFile dir = new File(sdcard.getAbsolutePath() + “/your-dir-name/”);// create this directory if not already createddir.mkdir();// create the file in which we will write the contentsFile file = new File(dir, “My-File-Name.txt”);FileOutputStream os = outStream = new FileOutputStream(file);String data = “This is the content of my file”;os.write(data.getBytes());os.close();