How to read à character ?
Hi,
I'm haveing a file of huge lines where each line ends with the character à
Reading the file as stream as follows:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
BufferedReader fileReader = new BufferedReader(new InputStreamReader(inStream));
String line;
while ((line = fileReader.readLine()) != null) {
stream.write(line.getBytes());
stream.write((byte) '\n');
}
return stream.toByteArray();
I get the each bytes and store the value in the stringbuilder without truncating the above character and converts the stringbuilder to string
The final converted string doesn't have the above latin character à
Is there is any way to get the string content along with the character à?
Thanks,
Kathir
Re: How to read à character ?
I don't really understand why you're converting the ascii characters into bytes. you might want to look at your use of the ByteArrayOutputScream aswell. You instantiate it but you never define a stream for it to write too in the constructor or later on.
Re: How to read à character ?
If that character is present in your input file it can only be there because of an encoding scheme (such as UTF-8 etc.) You should read that file using that encoding/decoding scheme. Possibly you should also write a file using the same encoding. Read the API documentation for the InputStreamReader class; it explains how to set an encoding scheme.
kind regards,
Jos
Re: How to read à character ?
When i conver the character to String using UTF-8 encoding i'm getting ?
Does the character represents the question mark?
Re: How to read à character ?
Quote:
Originally Posted by
j_kathiresan
When i conver the character to String using UTF-8 encoding i'm getting ?
Does the character represents the question mark?
No it doesn't; it represents a lower case 'a' with an 'accent grave' on top. So UTF-8 isn't the encoding used for your file. If you're running MS Windows most likely the encoding used is Windows-1252. Both the encoding and the decoding should be the same for simplicity reasons.
kind regards,
Jos