I. Basic outline
1. Description:
1> application operation requires some large data or images can be stored inside the phone
2> file Type: arbitrary
3> Path:/data/data/packagename/files/
4> Delete this data file when uninstalling an app
5> can also set permissions for manipulating data files (same as sharedpreferences)
Second, practice
1>fileinputstream fis=openfileinput ("logo.png"); Read file
2>fileoutputstream fos=openfileoutput ("Logo.png", mode_private); Save File
3>file Filesdir=getfilesdir (); Get Files Folder object
4> the file under Operation asserts:
. Context.getassets () gets Assetmanager
. InputStream open (filename); Read file
5> Loading picture files:
Bitmap bitmap=bitmapfactory.decodefile (String pathName); (drawable: Indicates that a picture object can be drawn)
Save diagram File:
1> get InputStream: Read assets under Logo.png
Assetmanager manager=getassets ();
2> reading files
InputStream Is=manager.open ("logo.png");
3> Get OutputStream:/data/data/packagename/files/logo.png
FileOutputStream fos=openfileoutput ("Logo.png", context.mode_private);
4> Read Side write:
Byte[] Buffer=new byte[1024];
int len=-1;
while ((Len=is.read (buffer))!=-1) {
Fos.write (Buffer,0,len);
}
Fos.close ();
Is.close ();
To read a picture:
1> Get picture path:/data/data/packagename/files
String Filespath=getfiledir (). GetAbsolutePath ();
String imgpath=filespath+ "/logo.png";
2> loading picture file to get Bitmap object:
Bitmap Bitmap=bitmapfactory.decodefile (Imgpath);
3> set it to ImageView display:
Iv_if.setimagebitmap (bitmap);
Third, the source code
Save Picture:
Assetmanager manager=getassets ();
InputStream Is=manager.open ("logo.png");
FileOutputStream fos= openfileoutput ("Logo.png", context.mode_private);
Byte[] Buffer=new byte[1024];
int len=-1;
while ((Len=is.read (buffer))!=-1) {
Fos.write (buffer, 0, Len);
}
Fos.close ();
Is.close ();
Toast.maketext (Mainactivity.this, "saved successfully", Toast.length_short). Show ();
To read a picture:
android-data storage of the internal phone file storage