I have a file whose contents are written in french. I want to read that file and edit the file and then write the contents back to the same file. How do I do that?I am reading file content is instanceof ByteBlock only. Then I am using byte[] blk = ((ByteBlock) content).bytes();FileOutputStream fs = new FileOutputStream("a.txt");fs.write (blk, 0, blk.length);fs.close();During writing a file I want use encoding like ISO-8859-1. I can't use Writer because my contents are byte stream. Same way I can't use BufferedOutputStream or DataOutputStream because its not supporting encoding. How do I solve this. Please help me.

Questions by bjmanu

Showing Answers 1 - 1 of 1 Answers

Rani Murali (rsk)

  • Nov 25th, 2006
 

ISO_8859_1 is the value range from 0-255. so if you use the data type which can hold upto 255, you can solve this.

Byte is equivalent of signed char i,e its range is from -128 to 127. so it cannot hold the special chars in its range.

instead you can use unsigned char[] for reading the contents.

To view the string representation of these char, appropriate locale needs to be set.

But please ensure that the current file content is in iso_8859_1 (not UTF8/UTF16). If so you need use the w_char and write your own encode and decode to convert the these to unicode values.

Note:All the above explanation is for the unix platform. I don't know how these things change on windows eventhough logically i don't suspect any problem.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.