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 •