Public voidbt7 (View v) {//determine if the SD card is mounted if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {//Get text Box contentsString ss=Et.gettext (). toString (); Try { //Write//1. Constructing the output stream//1) Get the path//get the SD card root directory//String path=environment.getexternalstoragedirectory (). Getcanonicalpath (); //get the directory that corresponds to the package nameString Path=getexternalfilesdir ("Music"). toString (); Toast.maketext (mainactivity. This, "path=" +path, Toast.length_long). Show (); //Construction FileFileOutputStream fos=NewFileOutputStream (path+ "/test.txt"); PrintStream PS=NewPrintStream (FOS); Ps.print (ss); Ps.close (); Fos.close (); Toast.maketext (mainactivity. This, "Write external success", Toast.length_short). Show (); } Catch(Exception e) {e.printstacktrace (); Toast.maketext (mainactivity. This, "Error storing file", Toast.length_short). Show (); } }Else{toast.maketext (mainactivity). This, "SD Card not Loaded", Toast.length_short). Show (); } } Public voidBt8 (View v) {if(Environment.getexternalstoragestate (). Equals (environment.media_mounted)) {Try{String path=getexternalfilesdir ("Music"). Getcanonicalpath () + "/test.txt"; FileInputStream FIS=NewFileInputStream (path); byte[]b=New byte[1024]; inti; String SS=""; while((I=fis.read (b)) >0) {SS+=NewString (b,0, i); } toast.maketext (mainactivity. This, "File contents" +SS, Toast.length_short). Show (); Fis.close (); } Catch(Exception e) {toast.maketext (mainactivity. This, "Error reading file", Toast.length_short). Show (); } } Else{toast.maketext (mainactivity). This, "SD Card not Loaded", Toast.length_short). Show (); } }
SD Memory Read