Question: please help with java assingment. my code is below - i ' m unsure how to write the reversed contents into a new file -
please help with java assingment. my code is below im unsure how to write the reversed contents into a new file please help, my code is below: package assignment;
import java.ioFile;
import java.ioFileWriter;
import java.ioIOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Reverse
public static void mainString args throws IOException
ArrayList lines new ArrayList;
Read and process command line arguments
int files ;num of command line args that are files
String inFile ;
String outFile ;
if argslength
usage;
System.exit;
else
Read the command line arguments
for int i ; i args.length; i
String arg argsi;
if CharacterisDigitargcharAti
usage;
return;
else
it is a file name
files;
if files
inFilearg;
else if files
outFile arg;
construct the scanner and print writer onjects for the reading and writing
File inputFile new FileinFile;
open file, reverse each line, and add it to the array list
tryScanner in new ScannerinputFile
while inhasNextLine
String line innextLine;
String reversed reverseStringline; calling a method
lines.addreversed;
write the output to the txxt file
tryFileWriter out new FileWriteroutFile
lines.forEachline
try
out.writeline;
catch IOException e
eprintStackTrace;
;
here
method reverses a string
static String reverseStringString r
String s ;
for int irlength; i; i
char c rcharAti;
s sc;
return s;
static void usage
System.out.printlnUsage: java reverse infile outfile";
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
