I need to write a file to my m/c.The file's content should be localized.Data is present in localized languages in database. I have constructed htmlstring based on that data.but when I open the file(fileNameString) using browser,I get all garbage.
How have you checked the contents of "htmlstring"? You need to be sure it really is correct.
Assuming "htmlstring" contains the correct characters, encoded in UTF-16 (that's how all Java Strings are encoded), then your code looks as if it would successfully write it to the file using UTF-8 encoding.
When you open a Web site via HTTP, the browser receives various HTTP headers. The "Content-Type" header is important for you. For a UTF-8 file, it would typically be "Content-Type: text/html; charset=UTF-8".
But when you open a local file in a Web browser, there are no HTTP headers (obviously). But you can include an HTML meta element to specify the encoding: