I'm really not sure that I understand well what you need to do. But considering that
- the connection is associated with an existing file on disk
- you definitely need to read from the file
- you might want to write to a file
Then you could do something like this if you forced UTF-8 encoding:
To check whether the previous content was encoded using UTF-8 or not, this is a completely different story, so this may or may not be useful in your case.
source share