Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Can anyone help me out?

  1. #1
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can anyone help me out?

    Hello everyone, I was wondering if you guys can help me out. I'm stuck on this assignment =(.......

    This is what I need to do...

    Write a program that analyzes a web server's log file to determine which computers have attempted to access that web server the most. Any class in the Java standard library is available for use on this assignment.

    So far this is what I got...

    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.*;
     
    public class logfile
    {
    	public static void main(String[] args) throws IOException
     
    	{
    		String filename; //file name
     
    		String log;
     
    		String s;
     
    		Map <String, Integer> name = new HashMap <String, Integer>();
     
     
    		//create scanner object for keyboard input
     
    		Scanner keyboard =  new Scanner(System.in);
     
    		System.out.println("Enter a log file to be analyzed");
     
    		filename = keyboard.nextLine();
     
    		FileReader f = new FileReader(filename);
     
    		BufferedReader inputFile = new BufferedReader(f);
     
    		log = inputFile.readLine();
     
    		while(log != null)
     
    		{
     
               Scanner read = new Scanner(f);
     
               // if we put this it will print out all the info inside the the logs
     
               /*
                * while(log! = null)
                * {
                * 	System.out.println(log);
                * 
                * 	log = input.File.readLine();
                * }
                */
               while(read.hasNext())
     
               {
                   while (read.hasNext())
     
                       if(read.next().contains("[client"))
     
                           break;
     
                   if(read.hasNext())
                   {
                       s = read.next();
     
                       s = s.substring(0, s.length()- 1);
     
                       System.out.println(s);
                   }
                   read.nextLine();
               }
    			log = inputFile.readLine();
    		}
     
    		System.out.println("Found " + "_______" + " unique IP addresses.");
     
    		System.out.println("The most suspicious are: ");
     
    		System.out.println()
     
    	}
    }
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by DK333; May 23rd, 2011 at 12:04 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can anyone help me out?

    Is there an error or problem? Can you explain what it is?

    Do you have any specific questions?

  3. #3
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anyone help me out?

    Well in my assignment I have to test 3 logs, right now I tried running one of the logs but it didn't seem to work. I don't have errors in my code.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can anyone help me out?

    it didn't seem to work
    Please explain in some more detail.
    Also add some debug println statements to the code to show variable values as they change.

  5. #5
    Junior Member
    Join Date
    May 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can anyone help me out?

    I put the log file inside the LogFileAnalysis folder, then I run the program and the only thing that outputs is "Enter a log file to be analyzed".

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Can anyone help me out?

    the only thing that outputs is "Enter a log file to be analyzed".
    What does the program do after it outputs that message?

    Add some debug println statements to the code to show where execution flow goes and the variable values as they change.

    For example show the value of log before entering the while statement?