Assets often can put some relatively large resources, for these resources how we access.
Steps
1. Get Assetmanager.
Assetmanager am = getresources (). Getassets ();
2. Open the corresponding input stream with the Assetmanager's open (String FilePath) method.
InputStream is = Am.open (assetsfilename);
Read picture file save to SD card sample code
PublicBooleanSavetosdcard(String Localfilepath, String fileName, Bitmap Bitmap) {String Extrapath = Environment.getexternalstoragedirectory (). toString ();//Use absolute pathExtrapath = Extrapath +"/"+"PaperCut"+"/"+localfilepath;//String path = null;File File =NewFile (Extrapath);if(!file.exists ()) file.mkdirs ();Try{FilePath = File.getpath () +"/"+ FileName +". png"; File NewFile =NewFile (FilePath);if(Newfile.exists ()) {Toast.maketext (Getapplicationcontext (), R.string. FINISHTIPS1,//have saved a proToast.length_short). Show ();return true; }Else{FileOutputStream FileOutputStream =NewFileOutputStream (FilePath); Bitmap.compress (Bitmap.CompressFormat.PNG, -, FileOutputStream);//end of another format //Bitmap.compress (Compressformat.png, fileoutputstream);Fileoutputstream.flush (); Fileoutputstream.close (); } }Catch(Exception e) {E.printstacktrace ();//System.out.println (e.tostring ()); return false; }return true; }PrivateBitmapGetimagefromassetsfile(intPosition) {//bitmap image = null;Bitmap image =NULL; String Assetsfilename =NULL; Assetsfilename ="album/"+ is. Imagemychoosename.Get(position) +"/1.png";//assetmanager getting resources from the assets folderAssetmanager am = getresources (). Getassets ();Try{InputStream is= Am.open (Assetsfilename);//Generate image from InputStream decodingImage = Bitmapfactory.decodestream ( is); is. Close (); }Catch(IOException e) {E.printstacktrace (); }returnImage }//CallSavetosdcard ("album","FilePath"), Getimagefromassetsfile (position));
Android access to files under assets