Given an initialized String variable fileName, write a sequence of statements that create a file whose name is given by the variable and whose content is a single line consisting of “This Is File: ” followed by the name of the file. 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.)

LANGUAGE: JAVA

CHALLENGE:

Given an initialized String variable fileName, write a sequence of statements that create a file whose name is given by the variable and whose content is a single line consisting of “This Is File: ” followed by the name of the file. 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.)

SOLUTION:

PrintWriter output = new PrintWriter(fileName);
output.println("This Is File: "+fileName);
output.close();