Erata/Corrections

satya - Thursday, February 11, 2010 1:04:24 PM

Chapter 3, page 59 of the book

The code "Listing 3-19. Reading a Raw Resource" should instead be

Credit

Many thanks to Eduardo Berton for pointing out


String getStringFromRawFile(Activity activity)
   throws IOException
   {
      Resources r = activity.getResources();
      InputStream is = r.openRawResource(R.raw.test);
      String myText = convertStreamToString(is);
      is.close();
      return myText;
   }

   String convertStreamToString(InputStream is)
   throws IOException
   {
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      int i = is.read();
      while (i != -1)
      {
         baos.write(i);
         i = is.read();
      }
      return baos.toString();
   }