I'm new to Java and I'm trying to create a file parser that reads through a text file and outputs certain lines to another text file with tab delimited spaces btween th data. The following is an example of the file I'm trying to parse:
Report: Fake Report for Fake Loans
Report ID: 000001
Run Date: 04/25/2007
----------------------------------------------------------------------
ASC Number Loan ID DelqMessage
033 000101000 N
034 001234875 Y
035 123456789 N
----------------------------------------------------------------------
ASC Number Loan ID DelqMessage
036 741258963 N
037 872563987 N
038 987521455 Y
================================================== ====================
Fake Report Summary:
ASC Total: 6
Loan Total: 6
Total Delq: 2
The output would like the following:
Rundate ASC LoanId Delq Message
4/25/07 031 1234567891 N
When I try to run the program I get the following error:
Exception in thread "main" java.lang.NoSuchMethodError: main
Anybody have any suggestions on what I need to do to resolve this error. Below is my current code.
import java.io.FileReader;
import java.io.FileWriter;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.IOException;
public class FileParse {
private static String[] junkRow;
public void main(String[] args) throws IOException {
// Variable Declaration
boolean procOn;
String RunDate = "";
BufferedReader inputStream = null;
PrintWriter outputStream = null;
junkRow = new String[6];
junkRow[0] = "Report";
junkRow[1] = "ASC Number";
junkRow[2] = "Fake Report";
junkRow[3] = "Loan Total";
junkRow[4] = "Total Delq";
junkRow[5] = "ASC Total";
// Following block of cod parses FakeReportToParse.txt and outputs
// needed portions of the report to characteroutput.txt
try {
procOn = false;
inputStream =
new BufferedReader(new FileReader("FakeReportToParse.txt"));
outputStream =
new PrintWriter(new FileWriter("characteroutput.txt"));
outputStream.println("Rundate\tASCNumber\tLoan\tDelqMessage");
String l;
while ((l = inputStream.readLine()) != null) {
if (l.indexOf("Run Date:") >= 0) {
RunDate = l.substring(10);
}
// Processing of report data
if(l.indexOf("ASC Number") >= 0) {
procOn = true;
}
if(l.indexOf("---") >= 0 || l.indexOf("===") >= 0) {
procOn = false;
}
// Output report data to new characteroutput.txt file
if(procOn) {
if(!isjunk(l)) {
String ASC = l.substring(0, 4).trim();
String LoanID = l.substring(15, 25).trim();
String DelqM = l.substring(30).trim();
{
outputStream.println(RunDate + "\t" + ASC + "\t" + LoanID + "\t" + DelqM);
}
}
}
}
} catch(Exception z){
System.out.println("Error: " + z.toString());
}
finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
// @return true if it's a junk row
// @return false if it's not
private boolean isjunk(String x){
for(int i = 0; i < junkRow.length;i++){
if(x.indexOf(junkRow[i]) >= 0) {
return true;
}
if(x.trim().length() < 1) {
return true;
}
} return false;
}
}
Thanks for your help