Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Homework help: Parse Apache log files

$
0
0
Hi I'm new to java and I have an assignment that I just cant figure out how to begin for the life of me and its due in 2 days. Can someone please help me write the code for the following?

Write a small program in Java that scans an Apache access_log (text file) and displays:

a) The dates and times of the earliest and latest requests in the log file
B)/>/> The number of times each request method (GET, PUT, POST, etc.) was used
c) If the log is in NCSA Combined format (vs. NCSA Common), how many requests came from:
i) Mozilla-based browsers
ii) Internet Explorer
iii) Other browsers

so far I've only been to figure out how to scan the document and I'm not even sure if that's right. Below is what I have so far.
   import java.io.File;
   import java.io.FileNotFoundException;
   import java.util.Scanner;

   public class TextScanner {

     private static void readFile(String fileName) {
       try {
         File file = new File(fileName);
         Scanner scanner = new Scanner(file);
         while (scanner.hasNext()) {
           System.out.println(scanner.next());
         }
         scanner.close();
       } catch (FileNotFoundException e) {
         e.printStackTrace();
       }
     }

     public static void main(String[] args) {
       if (args.length != 1) {
         System.err.println("usage: java TextScanner1"
           + "file location");
         System.exit(0);
       }
       readFile(args[0]);
     }
   }



Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>