I have a text file with words and numbers and I need to write a class that creates a new file identical to the first except it shows the average.
I just need code that identifies the integers and finds the average of them.
The file reads like:
blah blah 4 blah blah 2 3 blah 3 blah blah blah blah etc...
but on the new file the average will be on the bottom.
My code so far:
private File inFile;
private Scanner input;
private File outFile;
private PrintWriter output;
public fileCloner(String inFilename, String outFilename)
{
inFile = new File(inFilename);
outFile = new File(outFilename);
makeLinks();
writeFiles();
closeLinks();
public void makeLinks() throws FileNotFoundException
{
input = new Scanner(inFile);
output = new PrintWriter(outFile);
}
public void writeFiles()
{
while (input.hasNext())
{
String line = input.nextLine();
output.println(line);
}
output.println("\n");
output.println("The average is" + );
}
public void closeLinks()
{
input.close();
output.close();
}
Any help is appreciated, thanks in advance.