Question: CHALLENGE ACTIVITY 3 . 5 . 1 : File output. 5 2 2 5 6 2 3 5 7 8 1 9 4 cul 3
CHALLENGE
ACTIVITY
: File output.
culray
Jump to level
Integer bedCount and string friendName are read from input. A FileOutputStream named fileStream is declared and the file named data txt is opened. Then, a PrintWriter named bedFS is declared and associated with the file. Write the following to the opened file:
"Shopping List:"
bedCount, followed by beds for and friendName
Another
End each output with a newline. Finally, close the file.
Ex: If the input is zehra, then data txt contains:
Shopping List:
beds for zehra
Note: Data written to a file may be lost if the file is not closed.
import java.util. Scanner;
import java.ioPrintWriter;
import java.ioFileOutputStream;
import java.ioIOException;
public class FileOutput
public static void mainString args throws IOException
Scanner scnr new Scanner
System.in;
FileOutputStream fileStream null;
PrintWriter bedFS null;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
