2

I am trying to learn android programming. As a beginning, I am trying to understand the internal file system & accessing them. Any help is highly appreciated. Following are my challenges:

  1. How to create a 'TEST' folder through the android emulator/Android device monitor? I need to create the folder where the alarms, download, DCIM folder are present.
  2. What is the absolute directory path to the 'TEST' folder created? Is it possible to access the TEST folder using the code below:

    List<File> list = Environment.getDataDirectory()+"/TEST".listFiles();
    
  3. Does any permission to be mentioned in the manifest for read/write to internal storage?

PS: I use Android Studio.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Adi
  • 361
  • 1
  • 5
  • 23
  • 1
    have you read this: http://developer.android.com/training/basics/data-storage/files.html ? – Gavriel Jan 19 '16 at 16:18
  • Thanks @Gavriel . Will read it & see. Meanwhile can you please help me with the point 1? – Adi Jan 19 '16 at 16:45
  • it's not even clear whether you want a solution in Java or from the command-line via adb – Gavriel Jan 19 '16 at 16:47
  • Sorry for the confusion. I don't want to create the folder programatically. I just need to make folder named 'TEST' available in the internal storage. ( So that my code can assume that the particular folder will be available while execution) – Adi Jan 19 '16 at 17:09
  • http://stackoverflow.com/questions/13373489/adb-shell-command-mkdir-for-creating-a-directory might help – Gavriel Jan 19 '16 at 17:11
  • Why not to use the "files" folder? This folder you can access WITHOUT any permission needed. Its located under data/data/yourAppPkg/files – Martin Pfeffer Jan 19 '16 at 19:32

2 Answers2

2

You would want something along the lines of

File TEST = new File(Environment.getExternalStorageDirectory(), "TEST");
TEST.mkdir(); // make directory may want to check return value
String path = TEST.getAbsolutePath(); // get absolute path

and permissions

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

Further reference

Community
  • 1
  • 1
denixtry
  • 2,928
  • 1
  • 21
  • 19
0

File file = new File("storage/emulated/0","yourfoldername/");

This worked for me if this doesn't help, then in use

File(Environment.getobbdir(),"yourfoldername");

divine_rythm
  • 149
  • 3
  • 9