当前位置: 代码迷 >> Android >> android之转化inputstream替list
  详细解决方案

android之转化inputstream替list

热度:79   发布时间:2016-04-28 07:16:47.0
android之转化inputstream为list
package com.hz2hs.business;import java.io.InputStream;import java.util.ArrayList;import java.util.HashMap;import javax.xml.parsers.SAXParserFactory;import org.xml.sax.InputSource;import org.xml.sax.XMLReader;import android.content.Context;import android.database.Cursor;import android.database.sqlite.SQLiteDatabase;import com.hz2hs.xmlhandler.BusinessHandler;import com.hz2hs.xmlhandler.commHandler;public class BusinessDataManage {	/**	 * 通过imputStream获得xml并生成列表	 * 	 * @param is	 * @return	 */	public static ArrayList<HashMap<String, Object>> getListOfInputStream(			InputStream is) {		ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();		try {			SAXParserFactory factory = SAXParserFactory.newInstance();			XMLReader reader;			reader = factory.newSAXParser().getXMLReader();			// 为XMLReader设置内容处理器			reader.setContentHandler(new BusinessHandler(list));			// 开始解析文件			reader.parse(new InputSource(is));		} catch (Exception e) {			// TODO Auto-generated catch block			// System.out.println(e.toString());			e.printStackTrace();		}		return list;	}}
  相关解决方案