Android, i/o & XML Jdom

BlackAHgel

New Member
I have an XML file located in the assets folder. The XML file is parsed to Object without issues (so that means the XML is 100% correct).Now what I'm doing is I copy the XML file from the assets folder to the Internal Storage. When I try to open the copied XML file from the internal memory I always get an exception.\[code\]org.jdom.input.JDOMParseException: Error on line 660: At line 660, column 8: not well-formed (invalid token)\[/code\]When calling this line:\[code\]Document doc = (Document) builder.build(xmlStream); (Where xmlStream is InputStream argument)\[/code\]The file seems to be copied just fine, because I took the \[code\]xmlStream\[/code\]-argument, converted it to String, and printed it to the screen, and it looks fine. They key here is that the exception always says that the last position of the file is wrong. So the last char of the closing tag at the buttom of the file is '>' located in line 660 col 8.The Copy operation\[code\]public class InternalMemory { private static Context mContext; public static String INTERNAL_PATH; static { mContext = App.getContext(); INTERNAL_PATH = mContext.getApplicationContext().getFilesDir().toString(); } public static void SaveStream(InputStream is,String folder,String fileName) { String path = INTERNAL_PATH + "/"+folder+"/"; File file = new File(path); file.mkdirs(); path += fileName; OutputStream os; try { os = new BufferedOutputStream(new FileOutputStream(path,true)); write(is,os); os.flush(); os.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } private static void write(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[1024]; int read; while((read = in.read(buffer)) != -1){ out.write(buffer, 0, read); } }}\[/code\]
 
Back
Top