I am trying to write a single character in a text file.
I do:
BufferedWriter out = new BufferedWriter(new FileWriter("exemple.txt"));
out.write((char)174);
out.close();
My text file is supposed to contains 10101110, if I look it with a binary viewer. Instead of it, it shows 11000010 10101110. So it writes 194 174, which is not the expected result.
So how can I write a single character in java which will result the good binary value ?
You need to open the file using the appropriate character set. something like:
i would suggest reading a good tutorial which teaches the difference between bytes and chars and what a character set is.