The Artima Developer Community
Sponsored Link

Java Answers Forum
File Writer - about char oriented streams

3 replies on 1 page. Most recent reply: Jun 22, 2005 6:13 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 3 replies on 1 page
Ilario

Posts: 4
Nickname: karim2
Registered: May, 2005

File Writer - about char oriented streams Posted: May 31, 2005 1:40 AM
Reply to this message Reply
Advertisement
Hallo,
i ran this code:

import java.io.*;


public class MyIOTest {
public static void main(String[] args) throws IOException{
MyIOTest myiotest = new MyIOTest();
BufferedWriter out = new BufferedWriter(new FileWriter("prova.out"));
char[] ch = { 'a', 'b', 'c', 'd' };
char c = 32000;
String s = "abcd";
out.write(ch);
out.write(c);
out.write(s);
out.close();
}
}


i used a file writer so the output stream is 16 bit char oriented (also java native char is 16 bit Unicode); but if i open prova.out file with an Hex editor this is what i view:

61 62 63 64-3F 61 62 63-64 - abcd?abcd

why FileWriter wrote Ascii chars instead of Unicode chars?


Ilario

Posts: 4
Nickname: karim2
Registered: May, 2005

More details Posted: May 31, 2005 2:05 AM
Reply to this message Reply
Runned on win2k sp 4 with jdk 1.5.0_01

Ilario

Posts: 4
Nickname: karim2
Registered: May, 2005

Re: File Writer - about char oriented streams Posted: Jun 22, 2005 6:01 AM
Reply to this message Reply
i found myself.
readers and writers in their constructor calls InputStream adapters using the default system encoding charset.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: File Writer - about char oriented streams Posted: Jun 22, 2005 6:13 AM
Reply to this message Reply
I think you have to go with a FileOutputStream.
This way you have to convert your characters to unicode 'manually' before writing the code into the file, but at the end you should get your desired result.

Flat View: This topic has 3 replies on 1 page
Topic: Problem in "Thinking in Java 3trd edtion" Previous Topic   Next Topic Topic: a test for signature Kdwoijrngik

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use