Ok, I thought this would be simpler but I was probably wrong..
My parser works fine (directly with the connection works) so I’ve some BASIC problems with writing and reading a file on Android (aka Java) or with Input/Output Stream..
The problem is that I don’t know what’s not working.. I’m missing any permission? I’m missing something while writing or reading the file?
Here is the code:
URL url = new URL(urlXml);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader reader = sp.getXMLReader();
CustomXmlHandler handler = new CustomXmlHandler();
reader.setContentHandler((ContentHandler) handler);
String fileName = getFileName();
File f = getFileStreamPath(fileName);
if(!f.exists()) {
FileOutputStream fos = openFileOutput(fileName, Context.MODE_PRIVATE);
URLConnection conn = url.openConnection();
conn.setConnectTimeout(5000);
conn.setReadTimeout(10000);
InputStream in = conn.getInputStream();
byte[] buffer = new byte[1024];
int len = 0;
while((len = in.read(buffer)) != -1) {
fos.write(buffer, 0, len);
}
fos.close();
in.close();
}
FileInputStream fis = openFileInput(fileName);
reader.parse(new InputSource(new InputStreamReader(fis)));
fis.close();
myObject = handler.getMyObject();
Thanks in advance.. I’m getting crazy..
Actually this code it’s fine. The error was somewhere else.
I’ll leave the code here for someone else that is looking for something similar!
If I shouldn’t just tell me and I’ll remove it. 🙂