package com.chinacreator.process.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


public class ReadUtil {

	public static List<Map<?,?>> readTxt(String filename,String encode){ 
		List<Map<?,?>> list = new ArrayList<Map<?,?>>();
		BufferedReader br = null;
		try{
			br = new BufferedReader(new InputStreamReader(new FileInputStream(filename), encode));
			String data = br.readLine();
			while (data != null) {
					if(!data.trim().equals("")){
						data = data.substring(data.indexOf("{"));
						data = data.substring(data.lastIndexOf("{"),data.indexOf("}")+1);
						System.out.println(data.replace("\\", ""));
						Map<?,?> map =JsonUtil.jsonToMap(data.replace("\\", ""));
						list.add(map);
						System.out.println(map.get("userid"));
					}
					data = br.readLine();
			}
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			try {
				br.close();
			} catch (IOException e) {
				e.printStackTrace();
			}	
		}
		return list;
		}
}
