I am using GSON to parse some JSON feeds in various of my applications.
I used this tutorial and this code to make it work: http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html
InputStream source = retrieveStream(url);
Gson gson = new Gson();
Reader reader = new InputStreamReader(source);
//***************************************************
//Should I add some code here to save to SDCARD?
//***************************************************
SearchResponse response = gson.fromJson(reader, SearchResponse.class);
List<Result> results = response.results;
for (Result result : results) {
Toast.makeText(this, result.fromUser, Toast.LENGTH_SHORT).show();
}
My question is set in the comment: What should I do to save this InputStreamReader to my SDCArd for an offline use?
I Googled a lot but cannot find a way to achieve this.
I guess that once I will have the answer, I will replace the 3 first line of code with:
InputStream source = new InputStream("/sdcard/my_json_file.txt");
Thank a lot for any help, I guess I am not the only one that need to achieve that...
source
to the FileOuputStream you created - see below -source
Send this new stream to your InputStreamReader