在android4.0及4.1这两个版本中,我们可以操作内置内存卡(4.4是可以的),但是不可以一步到位创建文件完毕
</pre><p>如:</p><p><pre name="code" class="java">File file = new File(Environment.getExternalStorageDirectory().getPath() + "/Test/test/1.txt");
但我们可以循环创建出来,即先建/Test这一层目录,再建/test,最后再建/1.txt,
如下:
File file;
String path;
String paths[] = {"/Test","/Test/test","/Test/test/1.txt"};
String sdPath = Environment.getExternalStorageDirectory().getPath();
for(int i = 0 ; i < paths.length ; i ++)
{
<span style="white-space:pre"> </span>path = paths[i];
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>file = new File(sdPath + path);
<span style="white-space:pre"> </span>
<span style="white-space:pre"> </span>if(!file.exists())
<span style="white-space:pre"> </span>{
<span style="white-space:pre"> </span>file.mkdir();
<span style="white-space:pre"> </span>}
}
这样我们就可以在4.0或者4.1的版本中创建文件了