You can perform many file operation in Android. I described few of them here.
- Create directory
- Create directory and sub-directories in one instance
- Rename directory
- Delete directory
- List the contain of that directory
The code for the first one, create a single directory at the root of your external storage directory.
File dirMain = new File(extdir + File.separator + "com.acomputerengineer"); if(!dirMain.exists()) { boolean mkdir = dirMain.mkdir(); if(mkdir) { Log.e("test", "Directory " + dirMain.getPath() + " created successfully"); } else if(!mkdir) { Log.e("test", "Directory " + dirMain.getPath() + " not created"); } }
Result:

Now creating directory and sub-directories at the same time.
//example 1 File dirWithSubdir1 = new File(extdir + File.separator + "com.acomputerengineer" + File.separator + "testDir1" + File.separator + "testSubdir1"); if(!dirWithSubdir1.exists()) { dirWithSubdir1.mkdirs(); } //example 2 File dirWithSubdir2 = new File(extdir + File.separator + "com.acomputerengineer" + File.separator + "testDir2" + File.separator + "testSubdir2" + File.separator + "testSubSubdir2"); if(!dirWithSubdir2.exists()) { dirWithSubdir2.mkdirs(); }
Result:

Now rename the directory ‘dirWithSubdir1’ from the above example.
File renameDir = new File(extdir + File.separator + "com.acomputerengineer" + File.separator + "newTestDir1"); dirWithSubdir1.renameTo(renameDir);
Result:

Now deleting the directory.
dirWithSubdir1.delete();
Result:

Now listing the content of the directory by logging them into logcat.
String[] dirMainFiles = dirMain.list(); for (int i = 0; i < dirMainFiles.length; i++) { Log.e("test", "file " + i + " :" + dirMainFiles[i]); }
Result:

