• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Write to <appdir>/files/<anysubdir> robustly?

Hey,

I'm working on an application that involves writing files to the private files dir of an application. In the first stage I only had to write to the default files dir so I just used the openFileInput() method from an Activity (Context). Now that I've done that I was about to expand and write files in different directories for different purposes. This resulted in:

"java.lang.IllegalArgumentException: File foo/bar.txt contains a path separator"

This stackoverflow question explains the problem nicely. The suggested solution probably works but I'm wondering how I should implement it. I would like to feature the permissions and anything else that I might require to have robust I/O.

android - How to create files hierarchy in Anroids &#39;/data/data/pkg/files&#39; directory? - Stack Overflow

Also, in my experience, when API developers prohibit such a feature there's a reason for it. So if anyone has any thoughts on that, by all means enlighten me :)

Thanks!
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones