Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You are given a String variable named file. It contains the name of a one-line f

ID: 3533499 • Letter: Y

Question

You are given a String variable named file. It contains the name of a one-line file. Write a sequence of statements that make an exact copy of the file and give it the same name but with the string ".cpy" attached to the filename. Make sure that the data written to the file has been flushed from its buffer and that any system resources used during the course of running these statements have been released.(Do not concern yourself with any possible exceptions here-- assume they are handled elsewhere.)

Explanation / Answer

//function which when given the String file does what is asked.

void filecopy(String file)

{
Scanner scan = new Scanner(new FileReader(file));
String newFileName = file + ".cpy";
FileWriter cpyFile = new FileWriter(newFileName);

while(scan.hasNext())
{
cpyFile.write(scan.next());
}
scan.close();
cpyFile.close();

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote