Android starts with internal storage

Source: Internet
Author: User

1. Save the file in the device's internal private storage, other applications cannot access;

2. After the application is uninstalled, the file is automatically deleted.

3. Caching

-----------------------------

----------------------------Test---------------------------

-------------------------------------

-----------------Test---------------------

------------------input, deposit file------------------------------

Requires EditText and button

----------------------------------saved to the cache file---------------------------------------------------

1     //----------------saved to the buffer file----------------------2      Public BooleanSavecachefile (String filename,byte[]data] {3         BooleanFlag =false;4File File =Context.getfilesdir ();5FileOutputStream OutputStream =NULL;6         Try {7File folderfile=NewFile (File.getabsolutepath () + "/txt");//create file txt directory8             if(!folderfile.exists ()) {9Folderfile.mkdirs ();//Create a directoryTen             } One //outputstream = context.openfileoutput ("My.txt", A //context. mode_world_writeable); -outputstream=NewFileOutputStream (Folderfile.getabsolutepath () + "/" +filename); -Outputstream.write (data,0, data.length); the}Catch(Exception e) { -             //Todo:handle Exception - e.printstacktrace (); -}finally { +             if(OutputStream! =NULL) { -                 Try { + outputstream.close (); A}Catch(Exception E2) { at                     //Todo:handle Exception -                 } -  -             } -  -         } in         //System.out.println ("---->>" +file.getabsolutepath ()); -         //-->>/data/data/com.example.android_datastorage_internal/files to  +         returnFlag; -}

---------------------------

1     //-------------Traverse Content-------------------2      Public voidListcachefile () {3         4 //string[] Strings =context.filelist ();5 //For (String string:strings) {6 //System.out.println ("----->>" +string);//list folders: txt7 //        }8         //traversing Files9File file=Context.getfilesdir ();TenFile root=NewFile (File.getabsolutepath () + "/txt"); OneFile[] Listfile=root.listfiles (); A          for(File file2:listfile) { -SYSTEM.OUT.PRINTLN ("---->>" +file2.getname ());//list the files inside the folder Hello.txt -              the         } -     } -}

------Test----------------------------------------

1  Public void Test () {2         Fileservice service=New  Fileservice (GetContext ()); 3         // service.savecachefile ("Hello.txt", "Hello". GetBytes ()); 4         service.listcachefile (); 5         6     }

---------------------------

Android starts with internal storage

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.