How To Search Value From Textfile
I'm geting school information from server by using school name as parameter in URL now i m making my application offline .suppose if i get all schoolname from server and save in te
Solution 1:
Just open the text file and read all text, then it's up to you whether parse the JSON into objects or run an IndexOf on entire string.
Here's how to read text from a file,
public String readFile(File fFileIn) throws IOException{
if(fFileIn == null) return "";
if(!fFileIn.exists()) return "";
FileInputStream fis = new FileInputStream(fFileIn);
byte [] bContent = new byte[(int) (fFileIn.length() + 1)];
fis.read(bContent);
return new String(bContent, Charset.defaultCharset());
}
Solution 2:
When working with web services, it is recommended, that you maintain a local and persistent storage, for offline access.
Go through this tutorial: http://androidituts.com/android-sqlite-database-tutorial/
Only the part you need to change is, instead of:
Category_ID.add(Long.parseLong(object
.getString("school_id")));
Category_name.add(object.getString("name"));
You just need to write the insert query of database, which is also mentioned in the above tutorial.
Hope my recommendation suits you need...
Post a Comment for "How To Search Value From Textfile"