I am trying to write a java utility that writes out an UTF-8 file with just the characters I explicity write to the file. I wrote the following code to do the trick.
import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
public class FileGenerator {
public static void main(String[] args) {
try {
char content = 0xb5;
String filename = "SPTestOutputFile.txt";
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(filename), "UTF-8"));
bw.write(content);
bw.close();
System.out.println("Done");
} catch (IOException e) {
e.printStackTrace();
}
}
}
I also pass -Dfile.encoding=UTF-8 as a VM argument.
The character that I am trying to write does get written to the file but I also get a  before it so when I try to write out µ I actually get µ. Does anyone know how to correct this so that I always just get just µ?
Thanks