android-file Storage

Source: Internet
Author: User

Android file storage is divided into:internal storage(internal storage) and External storage(external storage such as SDcard)

Internal storage:

1. Internal storage is always present

2. The default can only be accessed by your own app (of course by setting MODE_PRIVATE让其他应用访问而且其他应用要知道你的包名因为file存储的地址在/data/data/packname ) below.

3. When you delete this app, these files will also be deleted

4. Access internal storage do not use the manifest inside add permission

5. General APK installed in the internal storage of course also can be set by the android:installlocation in manifest apk installed directory

6. The internal directory is divided into Filesdir and Cachedir can get his address by means of Getfiledir (), Getcachedir ()

7. In the internal storage placed files do not need to be deleted, if not deleted beyond the system to your size, the system will automatically delete your stored files without warning

8. Writing of internal files

String filename = "myfile"; String string = "Hello world!"; FileOutputStream outputstream;try {  outputstream = openfileoutput (filename, context.mode_private);  Outputstream.write (String.getbytes ());  Outputstream.close ();} catch (Exception e) {  e.printstacktrace ();}
9. Writing of temporary files for internal files


Public file GetTempFile (context context, String URL) {    file file;    try {        String fileName = uri.parse (URL). getlastpathsegment ();        File = File.createtempfile (FileName, NULL, Context.getcachedir ());    catch (IOException e) {        //Error while creating file    }    return file;}

External Storage

1. External documents are not necessarily always in.

2. External files can be read by other means

3. When you delete an app is a file or it will exist

4. If you write to an external file, you need to add permissions to the manifest: uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE"

If you want to read the tail of the external file to the current location of the version is not required to add permissions, but in order to ensure backward compatibility is best when reading the file also added permissions: Uses-permission android:name= "android.permission.READ_ External_storage "

Remark: Android:installlocation

Although apps is installed onto the internal storage by default, you can specify theandroid:installlocation attr Ibute in your manifest so your app is installed on external storage. Users appreciate this option when the APK size is very large and they has an external storage space that ' s larger than th e internal storage. For more information, see APP Install location.

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.