Original: http://blog.csdn.net/wjdarwin/article/details/7108606
Today, in the process of writing to SDcard, creating a folder and saving files to it, there is a series of questions to summarize here:
1. Be aware of the permissions issue first
<uses-permission android:name= "Android.permission.MOUNT_UNMOUNT_FILESYSTEMS" ></uses-permission>
<uses-permission android:name= "Android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>
Problems with the 2.file.createnewfile () method
No such file appears. The problem
It is important to note that you create a folder for the design file path and then create the file
String local_file = Environment.getexternalstoragedirectory (). GetAbsolutePath () + "/down/";
File F = new file (local_file);
if (!f.exists ()) {
F.mkdirs ();
}
String local_file = F.getabsolutepath () + "/" +filename;
File F = new file (local_file);
try {
if (!file.createnewfile ()) {
System.out.println ("File already exists");
}
} catch (IOException ex) {
System.out.println (ex);
}
Summary of questions about the Android File.createnewfile () method (RPM)