Answered step by step
Verified Expert Solution
Link Copied!

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
3.5.1: File output.
5225623578194cul3ray
Jump to level 1
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 39zehra, then data txt contains:
Shopping List:
+++
39 beds for zehra
+++
Note: Data written to a file may be lost if the file is not closed.
import java.util. Scanner;
import java.io.PrintWriter;
import java.io.FileOutputStream;
import java.io.IOException;
public class FileOutput {
public static void main(String args) throws IOException {
Scanner scnr = new Scanner(
System.in);
FileOutputStream fileStream = null;
PrintWriter bedFS = null;
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Demystified

Authors: Andrew Oppel

1st Edition

0072253649, 9780072253641

Students also viewed these Databases questions