0

I am failing to create a file in SD card root (/storage/5DF1-1011/).

Is this even possible or am I limited to the app folder (/storage/5DF1-1011/Android/data/com.my.test.sdcardtest/)?

piet.t
  • 11,718
  • 21
  • 43
  • 52
Jan Málek
  • 531
  • 8
  • 21
  • The root folder is owned and grouped for `root` so you just can write there if you´ve got a rooted device. – LenglBoy Apr 12 '18 at 10:52
  • 1
    Possible duplicate of [mkdir() works while inside internal flash storage, but not SD card?](https://stackoverflow.com/questions/35109307/mkdir-works-while-inside-internal-flash-storage-but-not-sd-card) – Somesh Kumar Apr 12 '18 at 10:57
  • https://commonsware.com/blog/2017/11/15/storage-situation-removable-storage.html – CommonsWare Apr 12 '18 at 11:04

1 Answers1

0

yes you can create file in external storage of Android.

for that you need to give first permission in manifest :

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

after that you can create file in external storage :

String filePath = Environment.getExternalStorageDirectory().toString() + "/fileName.mp3";

File file  = new File(filePath);
if (!file.exists()) {
  file.createNewFile();
}
Hitesh Sarsava
  • 666
  • 4
  • 15