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.
activity_main.xml code
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.stoarage.MainActivity" >
-
- <TextView
- android:id="@+id/textView1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/hello_world" />
-
- </RelativeLayout>
MainActivity.java Code:
- package com.example.stoarage;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileOutputStream;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipInputStream;
- import android.annotation.SuppressLint;
- import android.app.Activity;
- import android.os.Bundle;
- import android.os.Environment;
- import android.view.Menu;
- import android.view.MenuItem;@
- SuppressLint("SdCardPath")
- public class MainActivity extends Activity {@
- Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- String path = Environment.getDataDirectory().getAbsolutePath().toString() + "/storage/emulated/0/appFolder";
- File mFolder = new File(path);
- if (!mFolder.exists()) {
- mFolder.mkdir();
- }
- File Directory = new File("/sdcard/myappFolder/");
- Directory.mkdirs();
- }@
- Override
- public boolean onCreateOptionsMenu(Menu menu) {
-
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
-
- @
- Override
- public boolean onOptionsItemSelected(MenuItem item) {
-
-
-
- int id = item.getItemId();
- if (id == R.id.action_settings) {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
Add UserPermission in Android.MainFest.xml 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: