My need is based on client and server operation. From the client they
request some files. from the request i have to get the platform, based
on that i have to encode the filename in server and return the
reponse. so server will always in the same platform. Based on client
platform, i have to rturn response.
You seem to be under the impression that client/server protocols are supposed to decide their character encoding based on the client's OS and locale. That is not required. For example, the HTTP Accept-Charset header is allowed to be ignored. What is required (at least for IETF protocols) is the ability to use UTF-8, and to declare the encoding (e.g., Content-Type: text/html; charset=KOI8-R
).
Unless you have a compelling reason to do otherwise, I'd recommend sending your response in UTF-8. That's what ⅔ of the Web does.
The remaining question is how to determine the file encoding on the server. An approach that works most of the time is:
- If it validates as UTF-8, then assume it is UTF-8.
- Otherwise, assume the platform's default encoding (e.g.,
java.nio.charset.Charset.defaultCharset().name()
as recommended by Martin).
(If desired, you can also add detect for UTF-32 (with or without BOM) and/or UTF-16 (with BOM).)