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

Write a program that prompts the user to enter an input filename and an output f

ID: 3655751 • Letter: W

Question

Write a program that prompts the user to enter an input filename and an output filename. The program considers the input file to be a Java file (just assume it is) and writes to the output file all the lines that are not full-line comments. Take a look at the difference between the sample input and output files below to see what is removed, I can post hints to the discussion forum if it's not clear what to look for Test your program using HelloWorld.java. C: UsersaronDesktop>java question3 Enter input file name: HelloWorld.java Enter output file name : NoComnents.txt Processing complete. After completion, my updated program produces NoComments.txt with contents: public class HelloWorld{public static void main(String[] args){System.out.println("Hello World!"); //magical}Instead of prompting the user for filenames, collect them from the command line - input file first, output file second. If the user does not enter two arguments on the command line an appropriate error message should be displayed C:UsersaronDesktop>java question3 HelloWorld.Java NoComments.txt Processing complete. C:UsersaronDesktop>java question3 No command line arguments. Cannot proceed.

Explanation / Answer

import java.io.*; public class Hello { public static void run(int arg, File input, File output) throws IOException { //Read the input file String content = readFileAsString(input); PrintStream myStream = new PrintStream(new FileOutputStream(output)); try { myStream.println(content + " " + arg); } finally { myStream.close(); } } private static String readFileAsString(File file) throws IOException { byte[] buffer = new byte[(int) file.length()]; BufferedInputStream f = null; try { f = new BufferedInputStream(new FileInputStream(filePath)); f.read(buffer); } finally { if (f != null) try { f.close(); } catch (IOException ignored) { } } return new String(buffer); } }

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