84.0k views
3 votes
Declare a fileoutputstream named outstream and a printwriter named okrawriter. ex: if the input is sue, then contains: sue ordered okras

User Mcclosa
by
8.3k points

1 Answer

7 votes

Final answer:

To create a FileOutputStream and PrintWriter in Java, you need to declare and instantiate them with the appropriate constructors. Then, you can use the PrintWriter to write to a file, ensuring you close it afterward to release system resources.

Step-by-step explanation:

The question involves creating a file output stream and a print writer in Java. To declare a FileOutputStream named outStream and a PrintWriter named okraWriter, you would write the following code in Java:

FileOutputStream outStream = new FileOutputStream("output.txt");
PrintWriter okraWriter = new PrintWriter(outStream);

Then, you can write to the file using okraWriter. For example:

okraWriter.println("sue ordered okras");
okraWriter.close();

This will write the text 'sue ordered okras' to the file named 'output.txt'. Remember to close the PrintWriter after you're done to flush the buffer and release system resources.

User Juan Rojas
by
7.5k points