Analyze four data files named ascii1.txt, ascii2.txt, binary1.txt and binary2.txt. The ascii1.txt and ascii2.txt are character data such as:
123123 16 999 22 765400 800 600
The binary1.txt and binary2.txt files will also hold integers, but it will hold them in binary form (i.e., four bytes per integer).
Program should work for ANY files containing numbers in the format described above. The files can contain any number of numbers (there could be five, thirty, or seven hundred numbers, etc.) Each file is guaranteed to hold at least one integer.
Process the files in the following manner:
�Open ascii1.txt and add all of the integers together.
�Open the file ascii2.txt and add every other integer to get a sum. The
first number in the file is the first number added to the sum.
�Open the file binary1.txt and sum every other integer. The first number
in the file is the first number added to the sum.
�Open the file binary2.txt and give the sum of the first, last, and middle
elements of the file. Must use random access to get these values. Do not read, or access in any way, any of the other integers in the file other than the first, last and middle integers. Report what these three integers are, and their sum. It is guaranteed that binary2.txt will have an odd number of integers (and at least three integers).
The output of your program should have the following format:
Ascii1 file total is: 890960
Ascii2 file "every other" total is: 890122
Binary1 file "every other" total is: 890960
First, middle and last of ascii2: 123123 + 22 + 600 = 123745
General:
Write ONE program that processes all four files.
Code written so far (didn't investigate randomAccess yet)figure I'll need some while and if statements for each file being analyzed. FileReader line can't be broken and continued on next line or app will not compile.
import java.io.*;
import java.util.*;
public class ProcessFiles
{
public static void main(
String args[]) throws IOException
{
FileReader fr1 = new FileReader("E:\\My Documents\\OCC\\
JavaII\\Programs\\ProcessFiles\\dataFiles\\ascii1.txt");
FileReader fr2 = new FileReader("E:\\My Documents\\OCC\\
JavaII\\Programs\\ProcessFiles\\dataFiles\\ascii2.txt");
FileReader fr3 = new FileReader("E:\\My Documents\\OCC\\
JavaII\\Programs\\ProcessFiles\\dataFiles\\binary1.txt");
FileReader fr4 = new FileReader("E:\\My Documents\\OCC\\
JavaII\\Programs\\ProcessFiles\\dataFiles\\binary2.txt");
BufferedReader br1 = new BufferedReader(fr1);
BufferedReader br2 = new BufferedReader(fr2);
BufferedReader br3 = new BufferedReader(fr3);
BufferedReader br4 = new BufferedReader(fr4);
String s1 = br1.readLine();
String s2 = br2.readLine();
String s3 = br3.readLine();
String s4 = br4.readLine();
StringTokenizer st1 = new StringTokenizer( s1 );
StringTokenizer st2 = new StringTokenizer( s2 );
StringTokenizer st3 = new StringTokenizer( s3 );
StringTokenizer st4 = new StringTokenizer( s4 );
}
}