Results 1 to 5 of 5
Thread: How to read à character ?
- 02-04-2012, 11:27 AM #1
Member
- Join Date
- Feb 2008
- Posts
- 12
- Rep Power
- 0
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
- 02-04-2012, 11:42 AM #2
Member
- Join Date
- Oct 2011
- Posts
- 92
- Rep Power
- 0
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.
- 02-04-2012, 12:10 PM #3
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 02-04-2012, 04:50 PM #4
Member
- Join Date
- Feb 2008
- Posts
- 12
- Rep Power
- 0
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?
- 02-04-2012, 05:03 PM #5
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,380
- Blog Entries
- 7
- Rep Power
- 17
Re: How to read à character ?
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,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
How to read a Char character ?!
By Sary in forum New To JavaReplies: 4Last Post: 03-27-2010, 06:01 PM -
Read a single character entered
By mcmb03 in forum New To JavaReplies: 2Last Post: 01-31-2010, 10:30 PM -
How to read a letter instead of a character from a given sentences
By lclclc in forum New To JavaReplies: 8Last Post: 09-15-2009, 11:53 AM -
Read from a certain character to a certain character
By blackstormattack in forum New To JavaReplies: 0Last Post: 03-16-2009, 11:36 AM -
Read character from Image area
By sundarjothi in forum Advanced JavaReplies: 2Last Post: 01-12-2009, 05:00 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks