Use the openfileoutput () method of activity to save files. The files are stored in the mobile phone space. Generally, the mobile phone storage space is not very large, and it is okay to store some small files, it is not feasible to store large files such as videos. For large files like videos, we can store them in sdcard. What does sdcard do? You can think of it as a mobile hard disk or a USB flash disk. To use sdcard in the simulator, You need to first create an sdcard (of course, not a real sdcard, but an image file ). You can create sdcard along with the simulator created in eclipse, or you can use the doscommand to create it. In the DOS window, enter the tools directory of the android SDK installation path, run the following command to create an sdcard with a capacity of 2 GB. The file suffix can be obtained at will. IMG: mksdcard 2048 m d: \ androidtool \ sdcard. IMG
Access in the programSdcard, You need to apply for accessSdcard.The permission to access sdcard in androidmanifest. XML is as follows: <! -- Create and delete file permissions in sdcard --> <uses-Permission Android: Name = "android. Permission. mount_unmount_filesystems"/> <! -- Write data permission to sdcard --> <uses-Permission Android: Name = "android. permission. write_external_storage "/> to store files in sdcard, the program must first determine whether the mobile phone is equipped with sdcard and can read and write data. Note: The sdcard must be accessed in androidmanifest. if (environment. getexternalstoragestate (). equals (environment. media_mounted) {file sdcarddir = environment. getexternalstoragedirectory (); // get the sdcard directory file SaveFile = new file (sdcarddir, inititcast.txt "); fileoutputstream outstream = new fileoutputstream (SaveFile); outstream. write ("Chuanzhi podcast ". getbytes (); outstream. close ();} environment. the getexternalstoragestate () method is used Obtain the status of the sdcard. If the mobile phone has an sdcard and can be read and written, the returned status is environment. media_mounted. Environment. the getexternalstoragedirectory () method is used to obtain the sdcard directory. To obtain the sdcard directory, you can also write: file sdcarddir = new file ("/mnt/sdcard "); // get the sdcard directory file SaveFile = new file (sdcarddir, "itcast.txt"); // you can combine the above two sentences: file SaveFile = new file ("/mnt/sdcard/itcast.txt"); fileoutputstream outstream = new fileoutputstream (SaveFile); outstream. write ("Chuanzhi podcast test ". getbytes (); outstream. close ();
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.