Question: How do you ask the defined output class to print result in the output file as .txt
All other java classes seem to be working and runs alright but it fails to print out any data in the output folder. I have imported the PrintWriter, but it will not create the file
Code:
import java.io.IOException;
import java.io.PrintWriter;
public class Outputs
{
//INSTANCE FIELDS
private Solution cwsSolution;
private Solution bestSol;
// CLASS CONSTRUCTOR
Outputs()
{ cwsSolution = null;
bestSol = null;
}
// SET METHODS
public void setCWSSol(Solution cwsSol)
{ cwsSolution = cwsSol;
}
public void setOBSol(Solution obSol)
{ bestSol = obSol;
}
// GET METHODS
public Solution getCWSSol()
{ return cwsSolution;
}
public Solution getOBSol()
{ return bestSol;
}
//PUBLIC METHOD
printOutputFile()
public void sendToFile(String outFile)
{
try
{ PrintWriter out = new PrintWriter(outFile);
out.println("***************************************************");
out.println("* OUTPUTS *");
out.println("***************************************************");
out.println("\r\n");
out.println("--------------------------------------------");
out.println("Clarke & Wright Solution (parallel version)");
out.println("--------------------------------------------");
out.println(cwsSolution.toString() + "\r\n");
out.println("--------------------------------------------");
out.println("\r\n OUR BEST SOLUTION:\r\n");
out.println("--------------------------------------------");
out.println(bestSol.toString() + "\r\n");
out.close();
} catch (IOException exception)
{ System.out.println("Error processing output file: " + exception);
}
}
}