Android Write files and folders

Source: Internet
Author: User

</pre><span style= "font-size:18px" > First of all, before we start specific operations, we must be familiar with the constructor of the Android file class, see my article Android file class </span><span Style= "Color:rgb (51,51,51); font-family: ' Microsoft Yahei '; font-size:16.363636016845703px; line-height:35.99431610107422px; Text-align:center ">http://blog.csdn.net/hemeng2009/article/details/40398063</span><p></p> <p><span style= "Color:rgb (51,51,51); font-family: ' Microsoft Yahei '; font-size:16.363636016845703px; line-height:35.99431610107422px; Text-align:center "> second, define the requirements, select the constructor of the file class according to the files or folders. </span></p><p><span style= "Color:rgb (51,51,51); font-family: ' Microsoft Yahei '; font-size:16.363636016845703px; line-height:35.99431610107422px; Text-align:center "> Read and Write access: </span></p><p><span style=" Color:rgb (51,51,51); font-family: ' Microsoft Yahei '; font-size:16.363636016845703px; line-height:35.99431610107422px; Text-align:center "> Add read and Write permissions to androidmanifest file: </span></p><p><span style=" Color:rGB (51,51,51); font-family: ' Microsoft Yahei '; font-size:16.363636016845703px; line-height:35.99431610107422px; Text-align:center "></span></p><p align=" left "style=" Color:rgb (51, 51, 51); font-family:arial; font-size:13.63636302947998px; line-height:25.99431800842285px; " ><!--permission to write data to SDcard--></p><p align= "left" style= "Color:rgb (51, 51, 51); font-family:arial; font-size:13.63636302947998px; line-height:25.99431800842285px; " >    <uses-permissionandroid:name= "Android.permission.WRITE_EXTERNAL_STORAGE" ></p ><p align= "left" style= "Color:rgb (51, 51, 51); font-family:arial; font-size:13.63636302947998px; line-height:25.99431800842285px; " >    </uses-permission></p><p align= "left" style= "Color:rgb (51, 51, 51); font-family:arial; font-size:13.63636302947998px; line-height:25.99431800842285px; " >    <!--permissions to create/delete files in SDcard--></p><p align= "left" StYle= "Color:rgb (51, 51, 51); font-family:arial; font-size:13.63636302947998px; line-height:25.99431800842285px; " >    <uses-permissionandroid:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></p ><p align= "left" style= "Color:rgb (51, 51, 51); font-family:arial; font-size:13.63636302947998px; line-height:25.99431800842285px; " >    </uses-permission></p><p><span style= "Color:rgb (51,51,51); font-family: ' Microsoft Yahei '; font-size:16.363636016845703px; line-height:35.99431610107422px; Text-align:center "> folder: </span><span style=" LINE-HEIGHT:35.99431610107422PX; Color:rgb (51,51,51); font-family: ' Microsoft Yahei '; font-size:18px; Background-color:rgb (240,240,240); Text-align:center "></span></p><p><pre name=" code "class=" Java ">if ( Environment.getexternalstoragestate (). Equals (environment.media_mounted)//Determine if read/write permission is available
{
<span></span>file root = new File (Environment</span>.getexternalstoragedirectory (). GetPath () + "/ sign/");//constructor parameter is path
<span></span>if (!root.exists ())
<span></span>{root.mkdirs ();} <span style= "Font-family:microsoft yahei;color: #333333;" ><span style= "FONT-SIZE:12PX; line-height:35.99431610107422px; " ></span></span>
}

</pre><p></p><pre>
File:
File File = new file (Environment.getexternalstoragedirectory (). GetPath () + "/sign/", filename);//Note the selection of the constructor if (! File.exists ()) {<span style= "White-space:pre" ></span>file.createnewfile ();}


Android Write files and 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.