Android FileIO with Android

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Introduction

Reading and writing files in Android are not different from reading and writing files in standard Java. Same java.io package can be used. However, there is some specific related to the folders where you are allowed to write, permissions in general and MTP work arounds.

Remarks

Android provides means for sharing the file between multiple applications as documented here. This is not required if there is only one app that creates and uses the file.

Android provides alternative storage options like shared and private preferences, saved bundles and built-in database. In some cases, they are better choice than just using plain files.

Android activity does have few specific methods that look like replacements of the Java standard File IO methods. For instance, instead for File.delete() you can call Context.deleteFile(), and instead of applying File.listFiles() recursively you can call Context.fileList() to get the list of all your app specific files with somewhat less code. However, they do not provide extra functionality beyond standard java.io package.



Got any Android Question?