Creating Folder in Internal memory

try the below

File mydir = context.getDir("users", Context.MODE_PRIVATE); //Creating an internal dir;
if (!mydir.exists())
{
     mydir.mkdirs();
}     

Here is the code which I am using for creating files in internal memory :

    File myDir = context.getFilesDir();
    // Documents Path
    String documents = "documents/data";
    File documentsFolder = new File(myDir, documents);
    documentsFolder.mkdirs(); // this line creates data folder at documents directory

    String publicC = "documents/public/api." + server;
    File publicFolder = new File(myDir, publicC);
    publicFolder.mkdirs(); // and this line creates public/api.myservername folder in internal memory

To create directory on phone primary storage memory (generally internal memory) you should use following code. Please note that ExternalStorage in Environment.getExternalStorageDirectory() does not necessarily refers to sdcard, it returns phone primary storage memory

File mediaStorageDir = new File(Environment.getExternalStorageDirectory(), "MyDirName");

if (!mediaStorageDir.exists()) {
    if (!mediaStorageDir.mkdirs()) {
        Log.d("App", "failed to create directory");
        return null;
    }
}

Directory created using this code will be visible to phone user. The other method (as in accepted answer) creates directory in location (/data/data/package.name/app_MyDirName), hence normal phone user will not be able to access it easily and so you should not use it to store video/photo etc.

You will need permissions, in AndroidManifest.xml

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />

Tags:

Android