• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem : Writting Data Into File Using Channel

 
kayanaat sidiqui
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:

 
Ravikanth Boorugadda
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 122
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Rob for your precious comments and solution. It helps a lot.

Also Thanks to Ravikanth.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic