Make a New Folder on Internal Storage in Android

Let us see the steps on how to perform this task in android .Create new project with a valid name, once everything ready our projects looks like below screen.

projects looks

activity_main.xml code

  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:paddingBottom="@dimen/activity_vertical_margin"  
  6.     android:paddingLeft="@dimen/activity_horizontal_margin"  
  7.     android:paddingRight="@dimen/activity_horizontal_margin"  
  8.     android:paddingTop="@dimen/activity_vertical_margin"  
  9.     tools:context="com.example.stoarage.MainActivity" >  
  10.   
  11.     <TextView  
  12.         android:id="@+id/textView1"  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:text="@string/hello_world" />  
  16.   
  17. </RelativeLayout>  
MainActivity.java Code:
  1. package com.example.stoarage;  
  2. import java.io.File;  
  3. import java.io.FileInputStream;  
  4. import java.io.FileOutputStream;  
  5. import java.util.zip.ZipEntry;  
  6. import java.util.zip.ZipInputStream;  
  7. import android.annotation.SuppressLint;  
  8. import android.app.Activity;  
  9. import android.os.Bundle;  
  10. import android.os.Environment;  
  11. import android.view.Menu;  
  12. import android.view.MenuItem;@  
  13. SuppressLint("SdCardPath")  
  14. public class MainActivity extends Activity {@  
  15.     Override  
  16.     protected void onCreate(Bundle savedInstanceState) {  
  17.         super.onCreate(savedInstanceState);  
  18.         setContentView(R.layout.activity_main);  
  19.         String path = Environment.getDataDirectory().getAbsolutePath().toString() + "/storage/emulated/0/appFolder";  
  20.         File mFolder = new File(path);  
  21.         if (!mFolder.exists()) {  
  22.             mFolder.mkdir();  
  23.         }  
  24.         File Directory = new File("/sdcard/myappFolder/");  
  25.         Directory.mkdirs();  
  26.     }@  
  27.     Override  
  28.     public boolean onCreateOptionsMenu(Menu menu) {  
  29.         // Inflate the menu; this adds items to the action bar if it is present.  
  30.         getMenuInflater().inflate(R.menu.main, menu);  
  31.         return true;  
  32.     }  
  33.   
  34.     @  
  35.     Override  
  36.     public boolean onOptionsItemSelected(MenuItem item) {  
  37.         // Handle action bar item clicks here. The action bar will  
  38.         // automatically handle clicks on the Home/Up button, so long  
  39.         // as you specify a parent activity in AndroidManifest.xml.  
  40.         int id = item.getItemId();  
  41.         if (id == R.id.action_settings) {  
  42.             return true;  
  43.         }  
  44.         return super.onOptionsItemSelected(item);  
  45.     }  
  46. }  
Add UserPermission in Android.MainFest.xml

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

Now Run the Application by pressing Ctrl+F11 and see the output as show like below. Open the File Explorer -> Storage ->Sdcard -> myappFolder.

Final result:

Final result

Ebook Download
View all
Learn
View all