-1

I did check out the other questions that had been about this. But the provided solutions seemed to not work for me. I have an input file made of hexadecimal characters. After reading the characters in as a String my program calculates a CRC-16 value for the file. After doing to I need to Append that CRC-16 value to the end of the file. How can can I do this simply.

For example) Input file reads: 45 CRC-16: 7464 The original file should be append to read: 457464

I'm am not that well versed in file i/o and I have been quite dependent on the Scanner and URL classes for getting paths and reading data.

1 Answers1

-1

You can use a FileWriter, with the true parameter at the end which causes us to append to the file.

try(BufferedWriter bf = new BufferedWriter(new FileWriter(new File("path"),true))){
  bf.write(text to append);
}

You may find this tutorial helps: http://www.mkyong.com/java/how-to-append-content-to-file-in-java/

As suggested I've updated this to show try with resources, which means the writer will be correctly closed even if there is an exception.

saml
  • 794
  • 1
  • 9
  • 20