*
The moose likes Beginning Java and the fly likes Problem : Writting Data Into File Using Channel Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Problem : Writting Data Into File Using Channel" Watch "Problem : Writting Data Into File Using Channel" New topic
Author

Problem : Writting Data Into File Using Channel

kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Hi,

I am using the following code for writting data in to file --




but the output file is as follows--

t e s t []

that is output file is having space in between each letter and unable to identify the new line character.

Could you please tell me where m i doing wrong?

Is there any other way to write and/or append data to a file?

Thanks,
Kaya.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19684
    
  20

http://faq.javaranch.com/java/UseCodeTags, don't quote text. I've changed it for you, see how much better that looks.

I've tried your code, and the characters are written using the big-endian Unicode charset (UTF-16BE). That's because ByteBuffer.putChar always uses two bytes for a character.

You should try using a different Charset, and then encode the string instead:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ravikanth Boorugadda
Greenhorn

Joined: Apr 07, 2009
Posts: 3
The file is getting written with Unicode characters. Use any editor which supports unicode to read the file. I tried with textpad, it is working fine.
kayanaat sidiqui
Ranch Hand

Joined: Sep 04, 2008
Posts: 122
Thanks a lot Rob for your precious comments and solution. It helps a lot.

Also Thanks to Ravikanth.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Problem : Writting Data Into File Using Channel