Store, read--android application built-in folders

Source: Internet
Author: User

1. Store the data in the application's folder and read and write

The context provides two ways to open the I/O for the application folder and create a file if it does not exist

FileInputStream Openfileinputstream (String fileName);

Fileouputstream openfileoutputstream (String filename,int mode);

Mode

1. Mode_append: Append mode storage

2. Mode_private: Private mode storage, other apps cannot access

3. Mode_world_readable: Indicates that the current file can be read by another application

4. Mode_world_writeable: Indicates that the current file can be written by another application

Context provides a way to access application folders

File Getfilesdir (): Gets the absolute path of the folder

String[] FileList (): Gets all the data under the folder

DeleteFile (String fileName): Deletes the specified file under a folder

Instance

 Public classNewactivityextendsappcompatactivity {Private Static FinalString filename= "Firstsharedpreference"; @Overrideprotected voidonCreate (@Nullable Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Try{FileOutputStream fos=Openfileoutput (filename,mode_world_writeable); String Str= "I am good at Android"; byte[] bytes =str.getbytes (); Fos.write (Bytes,0, bytes.length); FileInputStream FIS=Openfileinput (FileName); InputStreamReader ISR=NewInputStreamReader (FIS); BufferedReader BR=NewBufferedReader (ISR); String Data= ""; StringBuilder SB=NewStringBuilder ();  while(data = Br.readline ())! =NULL) {sb.append (data); }        } Catch(FileNotFoundException e) {e.printstacktrace (); } Catch(IOException e) {e.printstacktrace (); }    }}

Store, read--android application built-in folders

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.