I am new to Java. I am trying to read from, ReadUnicodeEncodedPlainTextDocument.txt, a plain text file encoded
in Unicode, then select four particular lines, and then write those plain text lines to, WriteANSIencodedPlainTextSelectedFields.txt,
another file encoded in ANSI.
Using my code ConvertEncodedText.java:
import java.io.*;
import java.util.Scanner;
public class ConvertEncodedText
{
public static void main(String[] args) throws Exception
{
File f = new File("ReadUnicodeEncodedPlainTextDocument.txt");
Scanner scan = new Scanner(f);
String peek1, peek2, peek3, peek4;
boolean pk1 = false, pk2 = false, pk3 = false;
int count = 0;
while(scan.hasNext()) // begin search
{
peek1 = scan.nextLine();
if (peek1.startsWith("From"))
{
pk1 = true;
peek2 = scan.nextLine();
if(pk1 && peek2.startsWith("Date"))
{
pk2 =true;
peek3 = scan.nextLine();
if(pk1 && pk2 && peek3.startsWith("To"))
{
pk3 = true;
peek4 = scan.nextLine();
if(pk1 && pk2 && pk3 && peek4.startsWith("Subject"))
{
System.out.println("\n" + peek1 + "\n" + peek2 + "\n" + peek3 + "\n" + peek4);
count++;
pk1 = false;
pk2 = false;
pk3 = false;
}//if pk1 && pk2 && pk3 && peek4.startsWith("Subject")), print, begin new search
else
{
pk1 = false;
pk2 = false;
pk3 = false;
}//else begin new search
}//if(pk1 && pk2 && peek3.startsWith("To"))
else
{
pk1 = false;
pk2 = false;
pk3 = false;
}//else begin new search
}//if(pk1 && peek2.startsWith("Date"))
else
{
pk1 = false;
pk2 = false;
pk3 = false;
}//else begin new search
}//if (peek1.startsWith("From"))
}//while hasNext
System.out.println("\ncount = " + count);
}
}
As shown below, I would like to write to the following text file encoded in ANSI, WriteANSIencodedPlainTextSelectedFields.txt:
From: "Mark E Smith" <mesmith@ABCD.com>
Date: April 9, 2007 11:28:19 AM PST
To: <doug.ulrich@RFI.com>
Subject: FW: RFI Research Topic Up-date
From: "Mark E Smith" <mesmith@ABCD.com>
Date: May 26, 2007 11:14:12 AM PST
To: <doug.ulrich@RFI.com>
Subject: Batting Practice Sportsphere
From: "Mark E Smith" <mesmith@ABCD.com>
Date: May 30, 2007 11:53:45 PM PST
To: <doug.ulrich@RFI.com>
Subject: 3p meeting
From: "Mark E Smith" <mesmith@ABCD.com>
Date: June 20, 2007 4:09:10 PM PST
To: <doug.ulrich@RFI.com>
Subject: Question
count = 4
In order to produce the above text file,
I would like to read the following text file encoded in Unicode, ReadUnicodeEncodedPlainTextDocument.txt:
From: "Mark E Smith" <mesmith@ABCD.com>
Date: April 9, 2007 11:28:19 AM PST
To: <doug.ulrich@RFI.com>
Subject: FW: RFI Research Topic Up-date
Hi, Dr. Ulrich.? Are there any authors and titles of JME that you could recommend for my reading??
Thanks.? Mark
From: Joe Greene [mailto:greene@it.sdu.com]
Sent: Sat 4/7/2007 4:10 PM
To: Mark E Smith
Subject: RE: RFI Research Topic Up-date
?
Hi Mark,
?
Thanks for the update. I have met Dr. Ulrich on several occasions ? he is a great guy!
?
Dr. Hammer and I also have the same advisor from graduate school. He did his Masters with my PhD advisor at Poly-Tech. We have also met many times in the past. I think you will be in good hands down there.
?
It seems clear that you need to start learning JME and can perhaps forget about Windows Mobile. JME represents a smaller footprint for Java that contains support for various APIs for mobile functionality. I do not own any JME books, but a search on Amazon.com turned up what looks like several good ones.
?
Best wishes
?
?
Joe
?
----------------------------------------------------
Joe Greene, Ph.D.
DCSIT
it.sdu.com
greene@it.sdu.com
http://www.greene.org
From: Mark E Smith [mailto:mesmith@ABCD.com] 
Sent: Saturday, April 07, 2007 9:30 AM
To: greene@it.sdu.com
Subject: RFI Research Topic Up-date
?
Welcome to the conversation, Dr.Greene.? This is where we are so far.? I would appreciate your thoughts.
Thanks.? Mark
From: "Mark E Smith" <mesmith@ABCD.com>
Date: May 26, 2007 11:14:12 AM PST
To: <>
Subject: Batting Practice Sportsphere
Saturday, May 26, 2007
Hi, Dr. Ulrich.? This read-sensitive run-recognition pitching distribution is perhaps a commercial problem in a less sophisticated framework.? Could we build a simple commercial application and then customize the solution for the Ballpark functions and framework?? Thanks.? Mark
From: "Mark E Smith" <mesmith@ABCD.com>
Date: May 30, 2007 11:53:45 PM PST
To: <doug.ulrich@RFI.com>
Subject: 3p meeting
Hi, Dr. Ulrich.? Attached are a few notes from my research of the project docs that you sent me.? I am looking forward to our 3p meeting.??Thanks.? Mark?
From: "Mark E Smith" <mesmith@ABCD.com>
Date: June 20, 2007 4:09:10 PM PST
To: <doug.ulrich@RFI.com>
Subject: Question
Hi, Dr. Ulrich.? Pine-tar.? What do you think?? Would you please show me how to pitch sliders and splitters into this so I can study the features in detail?? Thanks.? Mark
?
P.S.
As you can see, my code reads the particular sequence of 4 selected fields, From, Date, To, and Subject,
out of an email that contains that specific sequence of 4 fields then I would like to place them in a text file
called WriteANSIencodedPlainTextSelectedFields.txt, and then print the number of emails in the document.
Instead of the desired output I would like to write to the file WriteANSIencodedPlainTextSelectedFields.txt; I am only getting this:
Count = 0
What is my problem???
Thanks,
Mike