Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Java Strings For this project, download the text file weblog.txt http://www.sant

ID: 3558061 • Letter: J

Question

Java Strings

For this project, download the text file weblog.txt http://www.santarosa.edu/~lmeade/weblog.txt
Note: To download this file, right click on the link and select SAVE AS.

This file is an Apache web log taken from the web server for St. Mary's University. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests. See below for a list of fields with an example:

Web Log Example

This file does not include all possible information that could be collected by a web server. The full description of the apache log file format can be found here: http://httpd.apache.org/docs/2.2/logs.html

For this project, you can use each line of the web log file as one string. An array of size 2990 will hold all of the lines in this file.

Minimum Requirements:

Explanation / Answer

import java.io.File;

import java.io.FileNotFoundException;

import java.io.PrintWriter;

import java.util.Arrays;

import java.util.Scanner;

?

public class ApacheWebLog {

static Scanner scan=new Scanner(System.in);

public static final String INPUT_FILENAME="weblog.txt";

public static final String OUTPUT_FILENAME="sorted_weblog.txt";

public static final int MAX=2990;

public static String[] fileContent=new String[MAX];

public static int count=0;

public static void main(String[] args) {

readFile();

sortFileContent();

writeFile();

}

public static void readFile()

{

try

{

File f=new File(INPUT_FILENAME);

Scanner br = new Scanner(f);

String sCurrentLine;

while (br.hasNext()) {

sCurrentLine = br.nextLine();

fileContent[count++]=sCurrentLine;

}

}

catch (FileNotFoundException e) {

System.out.println("File not Found");

}

}

private static void sortFileContent() {

Arrays.sort(fileContent);

}

private static void writeFile(){

PrintWriter out;

try {

out = new PrintWriter(new File(OUTPUT_FILENAME));

for (int i = 0; i < count; i++) {

out.println(fileContent[i]);

}

out.close();

} catch (FileNotFoundException e) {

System.out.println("File not Found");

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote