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

2018-06-18 02:39:00来源:未知 阅读 ()

新老客户大回馈,云服务器低至5折

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");        
        
    }

}

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:快速排序就这么简单

下一篇:动态代理和AOP