Write a sequence of statements that create a file named “greeting” and write a single line consisting of “Hello, World!” to that file. Make sure that the line has been flushed to the file 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:

Write an expression whose value is a reference to a newly created PrintWriter object associated with a file named Write a sequence of statements that create a file named “greeting” and write a single line consisting of “Hello, World!” to that file. Make sure that the line has been flushed to the file 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("greeting");
output.println("Hello, World!");
output.close();