Using a PrintWriter to write ASCII codes to a file?

A Writer writes characters, so the binary data that ends up in the file depends on the encoding.

A Writer writes characters, so the binary data that ends up in the file depends on the encoding. For example, if you have a 16-bit encoding like UTF-16 then there will be an extra zero byte for each ASCII byte: public class TestWriter { public static void main(String args) throws UnsupportedEncodingException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final OutputStreamWriter out = new OutputStreamWriter(baos, "UTF-16"); final PrintWriter writer = new PrintWriter(out); writer. Printf("abc"); writer.close(); for (final byte be : baos.toByteArray()) { System.out.

Printf("0x%02x ", b); } System.out. Printf("\n"); } } prints 0xfe 0xff 0x00 0x61 0x00 0x62 0x00 0x63.

It will output character data. But this can be beyond the ASCII set, which holds only 128 characters, of which the first 32 are special control characters.

You can write most ASCII letters as text or binary and you will get the same outcome with most characters encodings. Two of the ASCII characters have a special meaning in text files, are newline \n and carriage return \r. This means that if you have text file and you want to write a String which contains these characters it can be hard or impossible for the reader to distinguish between end-of-line in the text file e.g.Println() and end-of-line you put in a String e.g. Print("1\n2\n3\n").

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions