sromku/android-storage

Caused by: java.lang.IllegalArgumentException

palmAndroid opened this issue · 5 comments

I got following issue when i try to create directry and subdirectry with . extension like this .MainDirectry/.Subdirectry
Caused by: java.lang.IllegalArgumentException File app .MainDirectry/.Subdirectry contains a path separator
at com.sromku.simple.storage.InternalStorage.createDirectory(InternalStorage.java:41)

same issue for me...

i read the thread and others more but i can't get why the problem is present only in pre kitkat versions and how to resolve it continuing using this useful library.

Thanks

According to the guide:

Create sub directory.

// create directory
storage.createDirectory("MyDirName/MySubDirectory");

This throws an IllegalArgumentException: Path separator on Android version < 4.4

Can someone confirm? Thanks

For separators, please use File.separator instead of hard coded "/" char.
I made improvements in latest version. From now on, you will build absolute path by yourself. This code in new version should work for you:

// init
Storage storage = new Storage(context); 

// get path to internal storage files directory 
String filesDirectory = mStorage.getInternalFilesDirectory();

// create directory: /INTERNAL_STORAGE/files/MyDirName
String myDirName = filesDirectory + File.separator + "MyDirName";
storage.createDirectory(myDirName);

// create directory: /INTERNAL_STORAGE/files/MyDirName/MySubDirectory
String mySubDirectory = myDirName + File.separator + "MySubDirectory";
storage.createDirectory(mySubDirectory);

You can play with a new sample app and see this in action.
Hope it resolves your issue. Let me know if you have any questions.