2017-10-11 130 views
-1

時指數走出束縛我有我的txt文件裏的數據sotre的列表,它會像下面

陣列劈裂字符串

"[email protected]","10.9.2.34" 
"[email protected]","10.9.2.34" 
"[email protected]","10.9.2.34" 
"[email protected]","10.9.2.34" 
"[email protected]","10.9.2.34" 
"[email protected]","10.9.2.34" 

我會閱讀所有的輸入我的txt文件中,並存儲成DailyFileData。在那之後,我想從數據中提取出IP addressgmail.com,但是我無法做到這一點。mail1變量將存儲"[email protected]","10.9.2.34"從txt文件我已經搜索多個解決方案,以便如何在stackoverflow和其他網站中指定兩個分隔符。但我正在逐漸出現在下面的代碼行

String IP1 = Emaildata1[1]; 



這裏ArrayIndexOutOfboundException .The錯誤是我的源代碼

for(int c = DailyFileData.size()-1;c>=0;c--) 
     { 
     String mail1 = DailyFileData.get(c); 
     MailCount1 = Collections.frequency(DailyFileData,mail1); 
     System.out.println("Count of mail is :"+MailCount1); 
     String filename1 = f.getCanonicalPath(); 
     Pattern pattern = Pattern.compile("\\d{4}-\\d{2}-\\d{2}"); 
     Matcher match = pattern.matcher((CharSequence) filename1); 
     while (match.find()) 
     { 
      date1 = match.group(0); 
     } 
     String [] Emaildata1 = mail1.split(CSVSplitBy); 
     System.out.println(Emaildata1); 
     String domain1 = Emaildata1 [0]; 
     String IP1 = Emaildata1[1]; 
     String [] domainArray1 = domain1.split(emailSplitBy); 
     String domain2 = domainArray1[0]; 

     System.out.println("The extracted domain is :"+domain2); 
     System.out.println("The extracted date is :"+date1); 
     System.out.println("The extracted IP is :"+IP1); 
     domainAndCounting1.add(domain1); 
     domainAndCounting1.add(String.valueOf(MailCount1)); 
      Iterator<String> it = DailyFileData.iterator(); 
        while(it.hasNext()) 
          { 
          String mail2 = it.next(); 
          if(mail2.equals(mail1)) 
           { 
           it.remove(); 
           c--; 
           } 
          } 
      } 
+1

'mail1'的值是多少? –

+0

mail1是存儲ip地址和電子郵件ID的變量 – Lokesh

+0

是的,mail1將存儲IP和電子郵件地址,我已附上我的完整代碼 – yumi

回答

1

我不明白你想達到什麼樣的在你的代碼中。但如果你有String喜歡"[email protected]","10.9.2.34"和你正在試圖提取IP address和域名只有gmail.com,你可以簡單地嘗試以下方法,而不去模式匹配的任何併發症:

String a = "\"[email protected]\",\"10.9.2.34\""; 
     String arr[] = a.split(","); 
     System.out.println(Arrays.toString(arr)); 

     for (String aa : arr) { 
      if (aa.contains("@")) { 
       System.out.println(aa.substring(aa.indexOf("@") + 1, aa.length() - 1)); 
      } else { 
       System.out.println(aa.substring(1, aa.length() - 1)); 
      } 
     } 

N.B:這不是最好的解決辦法。這只是解決你的小問題。希望這可以幫助。

+0

謝謝,我解決了我的問題,這是由於我在代碼中犯了一些粗心的錯誤 – yumi