File Saving and Loading

In addition to the Android-specific data storage methods mentioned previously, the standard java.io.File Java package is available, too.This provides for flat file manipulation, such as FileInputStream, FileOutputStream, InputStream, and OutputStream.An example is reading from and writing to a file:

FileInputStream fis = openFileInput("myfile.txt"); FileOutputStream fos = openFileOutput("myfile.txt",

Context.MODE_WORLD_WRITABLE);

Another example is saving the bitmap camera picture to a PNG file, as follows: Bitmap takenPicture;

FileOutputStream out = openFileOutput("mypic.png",

Context.MODE_WORLD_WRITEABLE); takenPicture.compress(CompressFormat.PNG, 100, out); out.flush(); out.close();

The files in the resources directories can also be opened. For example, to open myrawfile.txt located in the res/raw folder, use the following:

InputStream is = this.getResource()

•openRawResource(R.raw.myrawfile.txt);

Character Building Thought Power

Character Building Thought Power

Character-Building Thought Power by Ralph Waldo Trine. Ralph draws a distinct line between bad and good habits. In this book, every effort is made by the writer to explain what comprises good habits and why every one needs it early in life. It draws the conclusion that habits nurtured in early life concretize into impulses in future for the good or bad of the subject.

Get My Free Ebook


Post a comment