Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

My Programming Lab REVEL Exercise: Given a Scanner reference variable, stdin, th

ID: 3929530 • Letter: M

Question

My Programming Lab REVEL Exercise:

Given a Scanner reference variable, stdin, that is associated with standard input, read in two words. Use the first word as the name of a file to create and store the second word in. Make sure that the data written to the file has been flushed from its buffer 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 handed elsewhere.)

***NOTE- you do not need the entire section of code, just need the part that does what the question asks. For example, REVEL will not recognize class names for this question as it is not given. It is just an exercise, not a full program.***

Explanation / Answer


import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class Excercise {
   void reader(Scanner sc) throws IOException
   {
       String name=sc.next();
       FileWriter fw=new FileWriter(name);
       String data=sc.next();
       fw.write(data);
       fw.flush();
       fw.close();
      
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote