I have an javafx application where I want new records to be add from quite complicated form. The form works properly and data is sent to writer class to actually write it to the text file, however, new lines are not add to file. I suspect that cause of this behavior is that file already opened for reading to show content in TableView but then I should have some exception thrown which I dont have. Controller method that calls writer looks like this:
@FXML
private void handleSubmit() {
String utc = "";
String filePath = mainApp.getAdifFilePath().getPath();
Adif2Writer writer = new Adif2Writer();
// get all records for the left side
try {
for (RecordGridController gridController : controllers) {
Map<String, String> recordData = gridController.getRecordData();
if (recordData.get("call") != null) {
Adif2Record record = new Adif2Record();
utc = recordData.getOrDefault("utc", utc);
String utcFormatted = LocalTime.parse(utc).format(DateTimeFormatter.ofPattern("HHmm"));
record.setCall(recordData.get("callC"));
writer.write(record, filePath);
}
}
// get all records for right side
for (RecordGridController gridController : controllers) {
Map<String, String> recordData = gridController.getRecordData();
if ((recordData.get("rstC") != null) && (recordData.get("rstC").length() > 1)) {
Adif2Record record = new Adif2Record();
utc = recordData.getOrDefault("utc", utc);
String utcFormatted = LocalTime.parse(utc).format(DateTimeFormatter.ofPattern("HHmm"));
record.setCall(recordData.get("callC"));
writer.write(record, filePath);
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
The writer method as following:
public void write(Adif2Record record, String filePath) throws IOException {
Adif2Wrapper wrapper = new Adif2Wrapper(record);
BufferedWriter bw = new BufferedWriter(new FileWriter(filePath, true));
bw.write(wrapper.toString());
System.out.println(wrapper.toString());
}
But when I press submit button there are no exceptions or warnings shown but file is not updated either wrapper.toString() return proper text though.