public static Map<Integer,List<String>> readTxt(File file){
//jt.readTxt(new File("C:/Users/Administrator/Desktop/aaaaa.txt"));
BufferedReader br = null;
Map<Integer,List<String>> map = new HashMap<Integer, List<String>>();
List<String> values = null;
int key = 1;
try {
InputStreamReader read = new InputStreamReader(new FileInputStream(file), "GBK");
br = new BufferedReader(read);
String temp = null;
while ((temp = br.readLine()) != null) {
if("".equals(temp)){
continue;
}
values = new ArrayList<String>();
StringTokenizer st = new StringTokenizer(temp);
while(st.hasMoreElements()){
String num = st.nextToken("\t").trim();
values.add(num);
}
map.put(key, values);
key++;
}
} catch (Exception e) {
e.printStackTrace();
}finally {
try {
if(null != br){
br.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return map;
}
public static void main(String[] args) throws SQLException {
JavaTools jt = new JavaTools();
Map<Integer,List<String>> map = jt.readTxt(new File("C:/Users/Administrator/Desktop/aaaaa.txt"));
Iterator<Entry<Integer, List<String>>> iterator = map.entrySet().iterator();
while(iterator.hasNext()){
Entry<Integer, List<String>> entery = iterator.next();
int key = entery.getKey();
List<String> values = entery.getValue();
System.out.print(key+":");
for(int i = 0 ; i<values.size() ; i++){
System.out.print(values.get(i)+"#");
}
System.out.println(" ");
System.out.println("==============================================");
}
System.out.println("-----------over");
}