Stats

46 Contributors: 2 Tuesday, January 3, 2017
Licensed under: CC-BY-SA
Not affiliated with Stack Overflow
Rip Tutorial: riptutorial@gmail.com
Roadmap: roadmap

FileIO with Android

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.

Related Examples