Okan Kocyigit
Okan Kocyigit

Reputation: 13421

How to create a folder in rootfolder in Android

As you can see in ss, some apps have created their own folders in my phone root folder.

So that means it's possible, but I couldn't find a way to do this.

enter image description here

Tried this but didn't work,

File folder = new File("/myfolder");
boolean success = true;
if (!folder.exists()) {
    success = folder.mkdir();
}

Upvotes: 2

Views: 167

Answers (2)

Burak Ogutken
Burak Ogutken

Reputation: 690

Java.IO.File folder = new Java.IO.File(
       Android.OS.Environment.ExternalStorageDirectory, "dalisto/cache");
folder.Mkdir ();

Upvotes: 0

user1837158
user1837158

Reputation:

You need to get put the path to sdcard first, like this:

File folder = new File(Environment.getExternalStorageDirectory(), "myfolder");
folder.mkdir();

You don't need to check if folder exists, as mkdir() will just do nothing (and return false) in that case.

Upvotes: 1

Related Questions