Android: Data --- File I/O
-
You can store to a file on the device.
-
Useful when
-
don't want a database
-
don't have name/value pairs used in SharedPreferences
-
or possibly when you have "a lot" of data
-
-
Two Options : Internal (device) and External Storage (SD Card --this is removable, so you can share with others or other devices)
Also you can read from Static (already in existence) resource file that is is res/ directory and will be part of apk of package.
You must state you will be doing writing to External Storage in permissions in AndroidManifest.xml
below we are asking to write to External storage
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="net.learn2develop.Files" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="10" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <application android:icon="@drawable/ic_launcher" android:label="@string/app_name" > <activity android:label="@string/app_name" android:name=".FilesActivity" > <intent-filter > <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
What about File Reading--- currently don't need permission but....future?
From android website: Currently, all apps have the ability to read the external storage without a special permission. However, this will change in a future release. If your app needs to read the external storage (but not write to it), then you will need to declare the READ_EXTERNAL_STORAGE permission. To ensure that your app continues to work as expected, you should declare this permission now, before the change takes effect.
<manifest ...>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
...
</manifest>