Adding this answer, so the question can be closed:
I see you are writing on output directly after closing cos which is created on top of output. This is not possible.
From the docu of CipherOutputStream.close(): "This method invokes the doFinal method of the encapsulated cipher object, which causes any bytes buffered by the encapsulated cipher to be processed. The result is written out by calling the flush method of this output stream. This method resets the encapsulated cipher object to its initial state and calls the close method of the underlying output stream."