As we saw in Chapter 1, Activities, Android provides a variety of methods for storing user preferences and settings but many applications require a more sophisticated filing system and a convenient way to do this is by using our handset's internal storage.
As one might expect the Java OutputStream object forms the basis for most of these types of operations.
Writing to internal storage is done through our Java activity class, so start up a new Android project in Eclipse and open the main activity pane.
Declare two string fields
FSPC
andmString
to act as our filename and content:final static String FSPC = "my_file.txt"; private final String mString = "a string";
Inside the
onCreate()
method add the following lines:FileOutputStream outStream; try { outStream = openFileOutput(FSPC, Context.MODE_PRIVATE); outStream.write(mString.getBytes()); outStream.close(); } catch (FileNotFoundException e) { e.printStackTrace();...