Parsing email source but it does not preserve the end of line seperator!
I am trying to parse some sendmail queue files which means I need to parse the header file to extract certain info and then prepend it to the message file. The problem is that depending on where the email is coming from it may contain various new line characters. For example, if I read it in with a BufferedReader it will drop the line seperator which may be a "CRLF" (carriage return line feed). How do I parse the lines without losing this information?
Make sense?
Thanks,
Michael
[508 byte] By [
heyblueza] at [2007-10-3 4:29:07]

Don't use a Reader, use one of the lower-level Stream classes. You could either read until you've encountered one of the new-line contructs, or tokenize the entire e-mail in some way (java.util.Scanner is preferred over StringTokenizer now, isn't it?)Brian
Read the API documentation (you can find it on the main java.sun.com site) for java.io.FileInputStream and java.util.Scanner. I don't know exactly what you're trying to do (except that you don't want to lose the EOL character(s)), so I can't write particularly useful code for you.
try {
File f = new File(pathToFile);
File o = new File(pathToOutput);
if (f.canRead() && o.canWrite()) {
FileInputStream fis = new FileInputStream(f);
... // read and parse
fis.close();
FileOutputStream fos = new FileOutputStream(o);
... // write results
fos.close();
} else {
// error, couldn't open required files
}
} catch (IOException ioe) {
// something bad happened during processing
}
Brian