Encoding Issue with Byte array java io classes supporting ISO-8859-1

Hi all,

I have an encoding propblem.

In my program i have to read/write some files (html)which are written in spanish/french/english.

Now for that reading the control goes to byte block,

i am sending the codes for reading but when i am modifying(as writing is enabled) the files.& trying to write back.

For that i need appending(writing) and encoding (i.e. "ISO-8859-1") toworked formy code.

I tried with FileWriter,OutputStreamWriter,FileOutputStream.

But unfortunately i haven't got any proper class or constructor which can give me this feature together, for " writing and encoding byte aray" as languages spanish/french will be special characters.



If anyone have any different solution.

Please let me know.

Reading code is this:

BufferedReader rdr = new BufferedReader(new InputStreamReader (new FileInputStream (filePath), "ISO-8859-1"));



the original code supporting only english is here:

else if (content instanceof ByteBlock) {
byte[] blk = ((ByteBlock) content).bytes();
if (blk != null)
{
FileOutputStream fs = new FileOutputStream
(path, append != null && append.booleanValue());
fs.write (blk, 0, blk.length);
fs.close();
}
}



For writing i tried its not sucessful:

BufferedWriter fs = new BufferedWriter(new OutputStreamWriter (new FileOutputStream (filePath),"ISO-8859-1"));



Or

For writing i tried its not sucessful:



FileOutputStream fs = new FileOutputStream
(filePath, append != null && append.booleanValue());
Writer out = new OutputStreamWriter(fs,"ISO-8859-1");


// FileWriter fs=new FileWriter(out);



String blk1 = content.toString();
fs.write (blk, 0,1);
fs.close();



Here in case of byte array may have to convert to char then FileWriter supports only. Some more trails are here.



if (content instanceof ByteBlock) {
byte[] blk = ((ByteBlock) content).bytes();

Encoding sjis = Encoding.getEncoding("ISO-8859-1");
// String unicodeString = sjis.getString(shift_jis_string);

if (blk != null)
{
FileOutputStream fs = new FileOutputStream
(path, append != null && append.booleanValue());

// StreamTokenizer output = new StreamTokenizer(fs,"ISO-8859-1");
//static FastWriter FastWriter.getInstance(Broker broker, java.io.OutputStream out, java.lang.String encoding)
//Get a new FastWriter


fs.write (blk, 0, blk.length);
fs.close();

// Open a TextWriter for the appropriate file
/* {
char[] c = new char[blk.length];
for (int i = 0; i >< blk.length; i++) {
c = (char)blk;
} */
//byte[] bytes = (new String(c, 0, c.length)).getBytes("ISO-8859-1");
// String roundTrip = FileUtils.fileContent (path).toString();
// bw.write (c, 0, c.length);
//bw.close();
// }
}
}




Please give me some better solution for this problem.



Thanks

Vijendra


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories