SD Memory Read

Source: Internet
Author: User

  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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.