I am retrieveing an XML feed from a url and then parsing it. What I need to do is also store that internally to the phone so that when there is no internet connection it can parse the saved option rather than the live one.
The problem I am facing is that I can create the url object, use getInputStream to get the contents, but it will not let me save it.
URL url = null;
InputStream inputStreamReader = null;
XmlPullParser xpp = null;
url = new URL("http://*********");
inputStreamReader = getInputStream(url);
ObjectOutput out = new ObjectOutputStream(new FileOutputStream(new File(getCacheDir(),"")+"cacheFileAppeal.srl"));
//--------------------------------------------------------
//This line is where it is erroring.
//--------------------------------------------------------
out.writeObject( inputStreamReader );
//--------------------------------------------------------
out.close();
Any ideas how I can go about saving the input stream so I can load it later.
Cheers
Simple Function
Try this simple function to neatly wrap it up in:
Thanks to Jordan LaPrise and his answer.
Here is a solution which handles all the Exceptions and is based on the previous answers:
A shorter version:
Here it is, input is your
inputStreamReader
. Then use same File (name) andFileInputStream
to read the data in future.There's the way of IOUtils:
The code of it is similar to this :