Newbie Help With File Parser
I have an assignment that involves using Java to parse the info on one text file and output to another text file with a header row and a data row both of which need to be tab delimited. I'm relatively new to Java and I'm having a hard time even starting this thing. Any help would be greatly appreciated. The file I have to read from is similar to this:
Report: Fake Report for Fake Loans
Report ID: 000001
Run Date: 04/25/2007
-
Office NumberID NumberDelqMessage
033000101000N
034001234875Y
035123456789N
I would essentially need to get all the field names into the header row and the data in the row below it.
Thanks in advance.
Google for the Java IO tutorial or seach around Suns website for it.
Read it, try some code and when you have a problem and a specific question, post back here and people can help you.
When you do post, include full error messages and indicate on which line they occur. The more info you provide the easier it is for people to help you.
I did some coding and was able to get the program to copy the file I need to parse into a new file. I was able to get another verision to parse out the file one word per line. However, I cannot seem to get the program to output one word per line in the other file. I tried putting in the s.useDelimiter to parse by whitespace and : which are the ways to breakup the words. However when I compile it I get the following error:
parsefile.java:12: cannot find symbol
symbol : variable s
location: class ParseFile
s.useDelimiter(":\\s*");
The following is the code I have set up:
import java.io.*;
import java.util.Scanner;
public class ParseFile {
public static void main(String[] args) throws IOException {
BufferedReader inputStream = null;
PrintWriter outputStream = null;
try {
inputStream =
new BufferedReader(new FileReader("FakeReportToParse.txt"));
s.useDelimiter(":\\s*");
outputStream =
new PrintWriter(new FileWriter("characteroutput.txt"));
String l;
while ((l = inputStream.readLine()) != null) {
outputStream.println(l);
}
} finally {
if (inputStream != null) {
inputStream.close();
}
if (outputStream != null) {
outputStream.close();
}
}
}
}
Anyone have any tips as to how to resolve the error or what I'm doing wrong?
Thanks
You're referring to an identifier "s", but haven't declared it anywhere.
The method on s that you're using, useIdentifier, is a method of Scanner.
My guess is that an earlier version of this program used Scanner, and you removed all references to it, except this line. Remove that line.