- The class contains a member variable of type
String , which is used to specify the name of the output file.
- The
FileWriter and
BufferedWriter used to write data to an external file, belong to the Java language rather than the
Simcenter STAR-CCM+ API. Use the constructor to create an output file and write a line of table headings.
|
public DataWriter(String fileToWrite) {
m_outputFile = fileToWrite;
try {
FileWriter fw =
new FileWriter(m_outputFile);
BufferedWriter bw =
new BufferedWriter(fw);
bw.write(“Angle (deg), DragCoefficient”);
bw.newLine();
bw.close();
} catch (Exception e) {
}
}
|
- The
writeDataLine() method opens the output file, adds a line that includes the cross-wind angle and the drag coefficient, then closes the file. The
newLine() method is included to move the cursor to the start of the next line in the output file. As the output data is contained in the
SimData object, the relevant object is passed to the method in the argument list.
- When the
FileWriter object is created in the method, you can see that one of the arguments is
true . This results in new data being appended to the end of the file.
|
public void writeDataLine(SimData sD) {
try {
FileWriter fw =
new FileWriter(m_outputFile, true);
BufferedWriter bw =
new BufferedWriter(fw);
bw.write(sD.getAngle() + “, “ + sD.getDrag());
bw.newLine();
bw.close();
} catch (Exception e) {
}
}
|