</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