所以我的程序编译但是在测试早期分析时我意识到它不会打印显示所有输出的文件。有人可以告诉我为什么文件根本没有被打印吗?这是我的代码...
import java.io.*;
import java.util.*;
public class Analyzer
{
private static FileWriter stream;
private static BufferedWriter output;
public static void start() throws IOException
{
int i = 0;
int total = 0;
int totalError = 0;
final int SIZE = 40000;
Response data[] = new Response[SIZE];
stream = new FileWriter("apacheOut.txt");
output = new BufferedWriter(stream);
Scanner scan = new Scanner("access_log1.txt");
scan.useDelimiter ("[-\t]+");
while (scan.hasNextLine())
{
double address = scan.nextDouble();
String date = scan.next();
String request = scan.next();
int status = scan.nextInt();
int bytes = scan.nextInt();
String refer = scan.next();
String agent = scan.next();
if (Integer.toString(status).substring(0, 1) == "4" || Integer.toString(status).substring(0, 1) == "5")
{
ErrorResponse er = new ErrorResponse (address, date, request, status, bytes, refer, agent);
totalError++;
}
else
{
SuccessResponse sr = new SuccessResponse (address, date, request, status, bytes, refer, agent);
}
total++;
}
int numGet = 0;
int numPost = 0;
double numBytes = 0;
for (i = 0; i <= SIZE; i++)
{
double address = data[i].getAddress();
String date = data[i].getDate();
String request = data[i].getRequest();
int status = data[i].getStatus();
int bytes = data[i].getBytes();
String refer = data[i].getRefer();
String agent = data[i].getAgent();
/** GET/POST count */
if (request.substring(0,1) == "G")
{
numGet++;
}
else if (request.substring(0,1) == "P")
{
numPost++;
}
/** Number of total bytes */
numBytes = bytes++;
}
output.write("Warren Smith's Results");
output.write("======================");
output.write("The total number of requests in the file: " + total);
output.write("The total number of GET requests: " + numGet);
output.write("The total number of POST requests: " + numPost);
output.write("The total number of bytes served: " + numBytes);
output.write("The number & percentage of pages producing various status categorizations:" );
output.write(" 1xx Informational: ");
output.write(" 2xx Status: ");
output.write(" 3xx Redirection: ");
output.write(" 4xx Client Error: ");
output.write(" 5xx Server Error: ");
output.write("The percentage and number of Windows-based clients: ");
output.write("The percentage and number of bad requests: ");
output.write("The percentage and number of clients that are Mozilla-based: ");
output.write("The percentage and number of requests from the Googlebot: ");
output.close();
}
}