My Programming Lab REVEL Exercise Given a Scanner reference
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.***
Solution
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();
}
}
