| Author |
Character encoding using Java
|
Jitesh Sinha
Ranch Hand
Joined: Jun 19, 2004
Posts: 144
|
|
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. Any pointers? Here is the code I am using :- FileOutputStream fos = new FileOutputStream(fileNameString, true); OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8"); osw.write(htmlstring); osw.close();
|
 |
Peter Chase
Ranch Hand
Joined: Oct 30, 2001
Posts: 1970
|
|
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: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> That might work.
|
Betty Rubble? Well, I would go with Betty... but I'd be thinking of Wilma.<br /> <br />#:^P
|
 |
 |
|
|
subject: Character encoding using Java
|
|
|