-1

Currently I am working with files in android and in order to create directory I used mkdir() command. The issue is, it worked on devices like Samsung,LG,Pixel and few others while it didn't work in One Plus of same API version. Replacing mkdir() with mkdirs() made it to work in one plus also. I would like to know how this varies from manufacturer to manufacturer.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

That's because the root folder in each manufacturer is different so when you call mkdirs() it will create the parent folder for your file so you don't need to address them yourself

masoud vali
  • 1,528
  • 2
  • 18
  • 29
  • Yeah mkdirs() creates parent folders but my directory structure was directory1/directory2. I wanted to know how just mkdir() made it to work in other devices because both directory1 and directory2 didn't exist. – Srinidhi Balakrishnan Nov 13 '18 at 09:54
  • this is the code: File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "/AppName/FlowName"); if (!file.exists()) file.mkdirs(); – Srinidhi Balakrishnan Nov 13 '18 at 13:20