Unicode OutputStream

I've currently got a class which does HTTP POST commands for me, and it uses a URLConnection to first connect to the target computer, and uses the OutputStream from getOutputStream of the URLConnection. Now, my program reads from a file and then uploads this data through the OutputStream, but the Unicode symbols in the file become garbled when they appear on the website (after having been POSTed by the program). After testing several input/output locations in my program, I've determined that the Unicode garbling happens at the upload.

My question is, how can I tell Java to upload the data in Unicode? Is it something I need to change to the OutputStream object, or to the URLConnection object?

[715 byte] By [GeneRayburna] at [2007-11-27 1:03:57]
# 1

OutputStreams have no concept of character encoding. They only work with bytes. If you are reading bytes and then writing bytes then the only thing you will need to do is set the content encoding header in the URLConnection.

In files, Unicode is normally represented by UTF-8, UTF16, UTF-16LE or UTF-16BE but you will need set the content encoding header to the encoding of your file.

sabre150a at 2007-7-11 23:39:02 > top of Java-index,Core,Core APIs...
# 2
So would the code be thenconnection.setRequestProperty("Content-Encoding", "UTF-8");for example? I wasn't sure about this before because it said request, i.e. only on the downloading side
GeneRayburna at 2007-7-11 23:39:02 > top of Java-index,Core,Core APIs...
# 3
I haven't used this for a couple of years so I'm not certain but I suspect you actually need to specify the Content-Type and give it a mime type and charset i.e "text/html; charset=utf-8".
sabre150a at 2007-7-11 23:39:02 > top of Java-index,Core,Core APIs...