doesn't run correctly
this code has no errors but when I run it it doesn't copy the text from the input file to the output file I'm
not sure what I'm doing wrong. for input i type in example.doc for output i type in example2.doc and it
doesn't copy the text maybe you could tell me what is wrong.
import java.io.*;
import java.util.*;
class FileCopy
{
publicvoid run(String inFileName, String outFileName)
{
int lineCount = 0;
try
{
//open a stream on a file (bytes)
FileInputStream inFile =new FileInputStream(inFileName);
//character based reading
InputStreamReader isr =new InputStreamReader(inFile);
//read a line at a time
BufferedReader reader =new BufferedReader(isr);
//write out to the file
FileWriter outFile =new FileWriter(outFileName);
String line =null;
//do this once for each line in the file
while ( (line = reader.readLine() )!=null )
{
lineCount++;
//write the line to the output file
outFile.write(line +"/n");
}
//close the output file object
outFile.close();
}
catch (IOException e)
{
System.err.println("IOException caught!");
}
System.out.println("Copied " + lineCount
+" lines from " + inFileName
+" to " + outFileName);
}
publicstaticvoid main(String[] args)
{
String inputFileName ="";
String outputFileName ="";
//if the user does not supply both an input and an output file name
if ( args.length < 2 )
{
//if no filename was given, complain
//System.out.println("Usage: FileCopy inFileName outFileName");
//System.exit(1);
//Why grouse? JUst ask for the file names...
try
{
InputStreamReader isr =new InputStreamReader(System.in);
BufferedReader reader =new BufferedReader(isr);
//neither was supplied, ask for the input first
if ( args.length < 1 )
{
System.out.print("Please provide an input file name: ");
inputFileName = reader.readLine();
}
else{ inputFileName = args[0];}
//ask for the output file name
System.out.print("Please provide an output file name: ");
outputFileName = reader.readLine();
}
catch (IOException e)
{
System.out.println("Could not read.");
return;
}
}
else//the names were supplied on the command line
{
inputFileName = args[0];
outputFileName = args[1];
//instantiates FileCopy and pass in the file names
FileCopy fc =new FileCopy();
fc.run(inputFileName, outputFileName);
}
}
}
this is what the output of the code sould look like
Please provide an input file name: example.doc
please provide an output file name: exaple2.doc
Copied 90 lines from example.doc to example2.doc

