Android开发时出现org.apache.harmony.xml.ExpatParser$ParseException:not well-formed错误时,我所犯的错误
2012-12-28 09:35
411 查看
这个错误搞了我一天了。原来我是做C#开发的,第一次做java,语法不是特别熟悉,另外Eclipse的开发环境也不熟悉。这个错误搞了我一整天了,搞得我都疲惫了,都准备放弃了,后来觉得,我这辈子为了一些看起来很重大的小事放弃了很多重要的人和事,觉得划不来,不能这样,更何况这是一些小事....算了,不八了。
本人的程序特点
1、服务器有个xml文件。
2、下载到本地的SD卡中
3、Android程序读取SD卡中的文件。
读取后报错说格式不对。
后来晚上,问一个朋友,他告诉我Eclipse有个DDMS可以查看SD卡的文件,我打开一看,原来真的下载到SD卡中的文件格式不正确。但服务器的格式是正确的,为什么这样呢?
后来查看了MARS老师写的FileUtils类,他的写入文件的函数利用的是byte[]方式写入,一开始,他定义的byte[] buffer = byte[4*1024],这么一个变量。
java的IO操作在读取FileInputSteam流的时候,如果读到最后了还没有填满这个buffer,则又从头开始读,一直要填满这个buffer,再给文件写入。
所以,下载到SD卡中的文件,一直是很大的,原因就是多了很多重复的数据。
后来,我把这个函数改成了一个byte一个byte的读,这样就不会出问题了,因为没有数据比一个byte还小吧。O(∩_∩)O哈哈~。
本人的程序特点
1、服务器有个xml文件。
2、下载到本地的SD卡中
3、Android程序读取SD卡中的文件。
读取后报错说格式不对。
后来晚上,问一个朋友,他告诉我Eclipse有个DDMS可以查看SD卡的文件,我打开一看,原来真的下载到SD卡中的文件格式不正确。但服务器的格式是正确的,为什么这样呢?
后来查看了MARS老师写的FileUtils类,他的写入文件的函数利用的是byte[]方式写入,一开始,他定义的byte[] buffer = byte[4*1024],这么一个变量。
java的IO操作在读取FileInputSteam流的时候,如果读到最后了还没有填满这个buffer,则又从头开始读,一直要填满这个buffer,再给文件写入。
所以,下载到SD卡中的文件,一直是很大的,原因就是多了很多重复的数据。
后来,我把这个函数改成了一个byte一个byte的读,这样就不会出问题了,因为没有数据比一个byte还小吧。O(∩_∩)O哈哈~。
output = new FileOutputStream(file); //byte[] buffer = new byte[1024]; int buffer; while((buffer = input.read()) != -1){ //output.write(buffer); output.write(buffer); } output.flush();
相关文章推荐
- 解析xml时,报错:org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 75:not well-formed
- 解析xml时,报错:org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 4:not well-formed(invaild toke)
- android用SAX解析xml文件时抛出org.apache.harmony.xml.ExpatParser$ParseException异常的解决方法
- 解析XML时,org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 449: not well-forme
- org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: unknown encoding
- 解析xml时,报错:WARN/System.err(207): org.apache.harmony.xml.ExpatParser$ParseException: At line 1,
- org.apache.harmony.xml.ExpatParser$ParseException mismatched tag
- org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: unknown encoding
- org.apache.harmony.xml.ExpatParser$ParseException: At line 1, column 0: unknown encoding
- 解析xml文件时,错误信息org.xml.sax.SAXParseException:Parser has reached the entity expansion limit "64,000" se
- android SAX解析xml流时报ExpatParser$ParseException错误解决方法
- sax解析xml运行出现错误org.xml.sax.SAXParseException: Content is not allowed in prolog.
- SAX解析错误,org.apache.harmony.luni.util.FloatingPointParser.parseDouble(FloatingPointParser.java:267)
- jsp页面报org.apache.el.parser.ParseException: Encountered 错误
- 解析xml文件时,错误信息org.xml.sax.SAXParseException:Parser has reached the entity expansion limit "64,000" set by the Application.的解决办法
- sax解析xml运行出现错误org.xml.sax.SAXParseException: Content is not allowed in prolog
- Android中使用DOM解析xml时出现org.xml.sax.SAXParseException: Unexpected token
- org.apache.el.parser.ParseException--异常
- org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or
- Spring如何加载XSD文件(org.xml.sax.SAXParseException: Failed to read schema document错误的解决方法)