8. Uh-oh! Looks like we have a problem with our submission. Your program is test
ID: 2246337 • Letter: 8
Question
8. Uh-oh! Looks like we have a problem with our submission. Your program is tested with 4 testcases (4 sets of input and output files). In order to pass all test cases, your program needs to produce the same output as the ones given below. (Even one character difference causes failure.) This is a part of Software Engineering Testing process (that we will be discussing in class). a. Download the following test cases by right-clicking on it and choosing Save Target in the same directory as AssignmentI.java is As.... Save them located. Input The attached files: input1.txt, input2.txt, input3.txt, input4.txt are the test cases that will be used as input for your program (Right-click and save): Output The attached files: outputl.txt, output2.txt, output3.txt, output4.txt (Right-click and save): Important Note: If you are downloading these files to a machine with Windows OS, an extra blank line will be added at the end of each file. However that lineExplanation / Answer
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.StringTokenizer;
public class FileOperationsCheck {
public static StringBuffer readFileOp(String fileName) {
BufferedReader> FileReader objFileReader = null;
StringBuffer buffer = new StringBuffer();
try {
// br = new BufferedReader(new FileReader(FILENAME));
objFileReader = new FileReader(fileName);
BufferedReader(objFileReader);
String objCurrentLine;
while ((objCurrentLine = onjBufferedReader.readLine()) != null) {
buffer.append(objCurrentLine);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (onjBufferedReader != null)
onjBufferedReader.close();
if (objFileReader != null)
objFileReader.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
System.out.println(buffer);
return buffer;
}
public static void writeFileData(String contentData, String fileName) {
BufferedWriter objBufferedWriter = null;
FileWriter objFileWriter = null;
try {
objFileWriter = new FileWriter(fileName);
objBufferedWriter = new BufferedWriter(objFileWriter);
objBufferedWriter.write(contentData);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (objBufferedWriter != null)
objBufferedWriter.close();
if (objFileWriter != null)
objFileWriter.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
public static void main(String[] args) {
System.out.println("File One Reading.. !");
StringBuffer inOne = FileOperationsCheck
.readFileOp("C:\test\file\filenameIn1.txt");
FileOperationsCheck.writeFileData(inOne.toString(),"C:\test\file\filenameOut1.txt");
System.out.println("File two Reading.. !");
StringBuffer inTwo = FileOperationsCheck
.readFileOp("C:\test\file\filenameIn2.txt");
FileOperationsCheck.writeFileData(inTwo.toString(),"C:\test\file\filenameOut2.txt");
System.out.println("File three Reading.. !");
StringBuffer inThree = FileOperationsCheck
.readFileOp("C:\test\file\filenameIn3.txt");
FileOperationsCheck.writeFileData(inThree.toString(),"C:\test\file\filenameOut3.txt");
System.out.println("File four Reading.. !");
StringBuffer inFour = FileOperationsCheck
.readFileOp("C:\test\file\filenameIn4.txt");
FileOperationsCheck.writeFileData(inFour.toString(),"C:\test\file\filenameOut4.txt");
}
}
Output is same as expected.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.