Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started