You might find some help at the Oracle developer documentations for Java.
SerialPort[
^] is what I found you're looking for. Do read that document, to learn how to extract data from a SerialPort and write the data (might be in form of bytes) to the file.