Read Log File Information

Source: Internet
Author: User

Problem:

F: // The format in the bb.txt log file is:

Get or post IP or domain name traffic (separated by spaces); get the traffic in which the submission method is get, and the IP address is the traffic limit and;

For example, get 127.0.0.1 15
Get www.sina.com 20
Get 192.168.0.1 33
Post 127.0.0.1 11
Get 128.123.0.1 11

The answer is: 59.

Public class iptest {<br/> Public static void main (string [] ARGs) throws ioexception {<br/> file = new file ("F: // bb.txt "); <br/> filereader Fr = new filereader (File); <br/> bufferedreader BR = new bufferedreader (FR); <br/> string I; <br/> List <string> List = new arraylist <string> (); <br/> while (I = BR. readline ())! = NULL) {<br/> list. add (I); <br/>}< br/> int sum = 0; <br/> for (INT m = 0; m <list. size (); m ++) {<br/> string a = List. get (m); </P> <p> int Re = iptest. sub (a); <br/> sum = sum + RE; <br/>}< br/> system. out. println (SUM); </P> <p >}< br/> Public static int sub (string a) {<br/> int K =. indexof (''); <br/> string AA =. substring (0, k); <br/> string B =. substring (k + 1); <br/> Int J = B. indexof (''); <br/> string AB = B. substring (0, J); <br/> string AC = B. substring (J + 1); <br/> If (AA. equals ("get ")) {<br/> string IP = "([1-9] | [1-9] // d | 1 // d {2} | 2 [0-4]/ /d | 25 [0-5]) (//. (// d | [1-9] // d | 1 // d {2} | 2 [0-4] // d | 25 [0-5]) {3} "; <br/> pattern P = pattern. compile (IP); <br/> If (P. matcher (AB ). matches () {<br/> return integer. parseint (AC); <br/>}< br/> return 0; <br/>}< br/>}

welcome:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.