Java Reference
In-Depth Information
import java.io.*;
public class CharacterCount
{
public static void main(String[] args)
throws FileNotFoundException, IOException
{
int lineCount = 0;
int [] letterCount = new int [26];
int next;
FileReader inputStream = new FileReader("text.txt");
PrintWriter outfile = new PrintWriter("textCh.out");
next = inputStream.read();
while (next != -1)
{
next = copyText(inputStream, outfile,
next, letterCount);
lineCount++;
next = inputStream.read();
}
//end while loop
writeTotal(outfile, lineCount, letterCount);
outfile.close();
}
//Place the definition of the method copyText, chCount,
//and writeTotal as described earlier here.
}
Sample Run:
Input file (text.txt)
Today we live in an era where information is processed
almost at the speed of light. Through computers, the
technological revolution is drastically changing the way we
live and communicate with one another. Terms such as
"the Internet," which was unfamiliar just a few years ago, are
very common today. With the help of computers you can send
letters to, and receive letters from, loved ones within
seconds. You no longer need to send a resume by mail to apply
for a job; in many cases you can simply submit your job
application via the Internet. You can watch how stocks perform
in real time, and instantly buy and sell them. Students
regularly "surf" the Internet and use computers to design
 
Search WWH ::




Custom Search