Tuesday 15 May 2012

utf 8 - Using java to write a UTF-8 File -


I am trying to write a Java utility that writes the UTF-8 file, just file with the characters I write to I wrote the following code to do the trick.

  import java.io.buffferedWriter; Import java.io.FileOutputStream; Import java.io.IOException; Import java.io.OutputStreamWriter; Public class FileGenerator {public static zero main (string [] args) {try {char content = 0xb5; String file name = "SPTestOutputFile.txt"; Buffed Vitaire BV = new buffed waist (new output-stream water (new file-output stream (filename), "UTF-8"); Bw.write (content); Bw.close (); Println ("full"); } Hold (IOException e) {e.printStackTrace (); }}}  

I also pass - Dfile.encoding = UTF-8 as a VM argument

The file I am trying to write is written to the file, but I get it before it even when I try to write, I actually get it. Know how to fix this that I always just get μ?

Thanks

This implementation works fine: μ is represented by UTF-8 c2 b5 . That's exactly what is written in the file.

Check UTF-8 table.

File in Hex Editor


No comments:

Post a Comment