You can store files directly on the mobile device or on a removable storage medium. By default, other applications cannot access these files.

To read data from a file, call Context.openFileInputO and pass it the local name and path of the file. It returns a standard Java FileInputStream object. To write to a file, call Context.openFileOutputO with the name and path. It returns a FileOutputStream object. Calling these methods with name and path strings from another application will not work; you can only access local files.

If you have a static file to package with your application at compile time, you can save the file in your project in res/raw/myDataFile, and then open it with Resources.openRawResource (R.raw.myDataFile). It returns an InputStream object that you can use to read from the file.

Was this article helpful?

0 0

Post a comment