Hi,
I have a file that has been encrypted (using bouncycastle for RSA encyption) but I now need to read from the file and get a String from it. I have used FileReader and Stringwriter to do so. The problem I have is that the FileReader.read() method is returning 65533 for a certain part of the file. But the StringWriter.write(int c) method seems to be writing with the value of 236 instead of the 65533. I have also tried using a FileInputStream instead of the file reader but to no avail. I suspect the problem is when the StringWriter writes the 65533 it gets converted due to the fact that the 16 high-order bits are ignored by the Writer class. I find this very strange as surely the 16 low order bits results in 65535 ((2^16)-1) which although very close to the 65533 is still higher than it. Is there a different class I could use to get the contents converted to a String? Below is a snippet of my code (using the FileInputStream):
FileInputStream inFile=new FileInputStream(filename);
StringWriter sw = new StringWriter();
int bit=0;
while ((bit = inFile.read())>=0){
sw.write(bit);
sw.flush();
}
return sw.toString();
Is it possible that the StringWriter.toString() method is actually the problem here?
Thanks,
Joe
I have a file that has been encrypted (using bouncycastle for RSA encyption) but I now need to read from the file and get a String from it. I have used FileReader and Stringwriter to do so. The problem I have is that the FileReader.read() method is returning 65533 for a certain part of the file. But the StringWriter.write(int c) method seems to be writing with the value of 236 instead of the 65533. I have also tried using a FileInputStream instead of the file reader but to no avail. I suspect the problem is when the StringWriter writes the 65533 it gets converted due to the fact that the 16 high-order bits are ignored by the Writer class. I find this very strange as surely the 16 low order bits results in 65535 ((2^16)-1) which although very close to the 65533 is still higher than it. Is there a different class I could use to get the contents converted to a String? Below is a snippet of my code (using the FileInputStream):
FileInputStream inFile=new FileInputStream(filename);
StringWriter sw = new StringWriter();
int bit=0;
while ((bit = inFile.read())>=0){
sw.write(bit);
sw.flush();
}
return sw.toString();
Is it possible that the StringWriter.toString() method is actually the problem here?
Thanks,
Joe