Android file storage

Source: Internet
Author: User
How to create folders and modify permissions in Android

Each application package has a private data storage directory. Only the application that belongs to this package has the permission to write data to this directory. Its absolute path: /data/<package name>/directory. In addition to Private Data Directories, applications can also read and write sdcards. Third-party applications cannot be written to other system directories in the file system.


// Create a folder

File destdir = new file ("/data/<package name>/<folder> ");

If (! Destdir. exists ()){
Destdir. mkdirs ();
}

// Modify permissions

Fileoutputstream Fos;
Fos = openfileoutput ("FILENAME", mode_world_readable );

/* Mode:

Public static final int mode_private = 0x0000; // The owner can access and overwrite and save data.
Public static final int mode_world_readable = 0x0001; // The owner can access and append the data to save.
Public static final int mode_world_writeable = 0x0002;
Public static final int mode_append = 0x8000;

*/

// Sdcard. You must first determine whether the sdcard is inserted.

String status = environment. getexternalstoragestate ();
If (status. Equals (environment. media_mounted )){

Return true;
}

Else {

Return false;
}

// Obtain the absolute path of the sdcard

Enviroment. getexternalstoragedirectory ();

// Obtain the absolute path of the phone memory (/data/<pacage Name>/files)

Activity. getfilesdir ();

// Obtain the cache directory (/data/<pacage Name>/cache );

Activity. getcachedir ();

Related Article

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.