File reading is important in android. For the put the files in the assets folder.

We can able to read

  • foldername
  • filename
  • Contents of the file

First we read the name of the folder.

private String folder_array[];
AssetManager mngr_spinner = getAssets();
try
{
         //"air" is the name of the folder...
	folder_array= mngr_spinner.list("air");
}
catch (IOException e1)
{
	e1.printStackTrace();
}

“folder_array” contains all the names of the folder
Then if the path is set to

folder_array= mngr_spinner.list("air/Buttons Events");

Then the list of file name is got.
If you want to read the file content then do the following..

InputStream is;
try
{
	is = getAssets().open(air/Buttons Events/filename);
	int siz = is.available();
	byte[] buffer = new byte[siz];
	is.read(buffer);
        //This text contains the content of the file..
	String text = new String(buffer);
        is.close();
}
catch (Exception e)
{
	 Toast.makeText(CheatSheet.this,"File Not Found Error.Please ensure that file is not deleted.", Toast.LENGTH_SHORT).show();
}
 

2 Comments

  1. dbv May 1, 2011 at 12:20 am

    Hi Guys. Great site.

    Android question: Say person has an eReader app (eg Kindle or others). Is it possible for another app to know what book titles have been downloaded or streamed?

     
  2. Pingback: Saving TextFile to SDCARD in android? | Coderz Heaven

Leave a Reply

Your email address will not be published. Required fields are marked *

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.