Input and output stream _ internal Storage ·

Source: Internet
Author: User

 Public voidBT3 (View v) {Try {             //writing files from memory//1. Get the internal storage directoryFile file=Getfilesdir (); String s=File.getabsolutepath (); Toast.maketext (mainactivity. This, "path=" +s, Toast.length_short). Show (); //2. Writing to a file with an output streamFileOutputStream fos=openfileoutput ("Test.txt", mode_private); //3. Writing file ContentsPrintStream ps=NewPrintStream (FOS); String SS=Et.gettext (). toString ();        PS.PRINTLN (ss); Ps.print (Test);        Ps.close ();        Fos.close (); Toast.maketext (mainactivity. This, "Saved successfully", Toast.length_short). Show ();} Catch(Exception e) {}} Public  voidBt4 (View v) {Try {        //input StreamFileInputStream fis=openfileinput ("Test.txt"); //definition byte[]            byte[]b=New byte[1024]; inti; //cyclic readingString str1= "";  while((I=fis.read (b)) >0) {str1=NewString (b,0, i);            } et2.settext (STR1);    Fis.close (); } Catch(Exception e) {}} Public  voidBt5 (View v) {Try{            //1. Get AssetsmanagerAssetmanager Assetmanager=getassets (); //2. Manipulate the asset catalog, read-write side-by- side//1) Read file to memory InputStreamInputStream InputStream = Assetmanager.open ("Aa.jpg"); //2) Write file to directory OutputStreamFileOutputStream fos=openfileoutput ("A.jpg", mode_private); //Read and write first            byte[] b=New byte[1024]; intI=0;  while((I=inputstream.read (b)) >0) {Fos.write (b,0, i);            } fos.close ();            Inputstream.close (); //write first and then readToast.maketext (mainactivity. This, "Save file succeeded", Toast.length_short). Show (); }        Catch(Exception e) {toast.maketext (mainactivity. This, "Error saving file", Toast.length_short). Show (); }    }    //set a picture to point to internal storage     Public  voidBt6 (View v) {//Get file pathString Path=getfilesdir (). GetAbsolutePath () + "/a.jpg"; //get Bitmap from the images stored internally//bitmapfactory.decodefile ("File path");Bitmap bm=bitmapfactory.decodefile (path); //set picture source for picture ViewIv.setimagebitmap (BM); }

Input and output streams internal storage •

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.