Public voidSave (View v) throws IOException {//1. Determine the status of the SD card, if the status is mounted to continue, otherwise prompt if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {//2. Read the input file name/contentString FileName =Et_of_name.gettext (). toString (); String content=Et_of_content.gettext (). toString (); //3. Obtaining the OutputStream of the specified file//1). Get the files path under the SD cardString Filespath = Getexternalfilesdir (NULL). GetAbsolutePath (); //2). Make a full pathString FilePath = filespath+"/"+FileName; //3). Create FileOutputStreamFileOutputStream fos =NewFileOutputStream (FilePath); //4. Write DataFos.write (Content.getbytes ("Utf-8")); Fos.close (); //5. TipsToast.maketext ( This,"Save Complete",0). Show (); } Else{Toast.maketext ( This,"SD card not mounted",0). Show (); } }
Saving data to an SD card