In android application sometime we need to store files in our asset folder .I have used this method in many of my application and it works perfectly .To read a file from the Asset folder you just need to call this method  .
public static String ReadFromAssetFile(Context context,String filename) {
         String content = "";
         InputStream inputStream = null;
         try {
                inputStream = context.getAssets().open(filenames);
                BufferedReader readerRead1 = new BufferedReader
(new InputStreamReader(inputStream));
(new InputStreamReader(inputStream));
 String line="";
while((line=readerRead1.readLine())!=null){
content+=line.trim();
 }
} catch (IOException e1) {
                                    // TODO Auto-generated catch block
                                     return content;
 }
                return content;
}  
Enjoy.... 
Do post your doubts, queries or suggestions in this blog.
 
No comments:
Post a Comment