欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

将文本中不同行内容分别存放

程序员文章站 2022-09-26 12:58:44
public class KL { public Map> CalcuP(String path) throws IOException { Map> map=new HashMap>(); BufferedReader reader = new BufferedReader(new Fi... ......
public class KL {
    public Map<String, ArrayList<String>> CalcuP(String path) throws IOException  
    {      
       
        Map<String, ArrayList<String>> map=new HashMap<String, ArrayList<String>>();    
        
         BufferedReader reader = new BufferedReader(new FileReader(path));
          String line = null;
          ArrayList<String> list = new ArrayList<String>();
          while ((line = reader.readLine()) != null) {
           list.add(line);
          }
                    
          reader.close();            
          String list0 = list.get(0);
          String list1 = list.get(1);
          String list2 = list.get(2);
          String list3 = list.get(3);
          ArrayList<String>    splist1=new ArrayList<String>(Arrays.asList(list0.split("\t")));
          ArrayList<String>    splist2=new ArrayList<String>(Arrays.asList(list1.split("\t")));
          ArrayList<String>    splist3=new ArrayList<String>(Arrays.asList(list2.split("\t")));
          ArrayList<String> splist4=new ArrayList<String>(Arrays.asList(list3.split("\t")));
          map.put("a",splist1);
          map.put("b",splist2);
          map.put("c",splist3);
          map.put("d",splist4);
          return map;
    }      
    
      
          
         
    public static void main(String[] args) throws IOException {
        KL t=new KL();
        String path=("filename");
        Map<String, ArrayList<String>> map=t.CalcuP(path);
        ArrayList<String> a = map.get("a");
        ArrayList<String> b = map.get("b");
        ArrayList<String> c = map.get("c");
        ArrayList<String> d = map.get("d");        
        
    }

}