Re: Stupid question regarding encoding
"Gordon Beaton" <n.o.t@for.email> wrote in message
news:45db0e7c$0$31542$8404b019@news.wineasy.se...
On Tue, 20 Feb 2007 15:42:24 +0100, Daniel Moyne wrote:
Then I do this :
BufferedReader entree=new BufferedReader(new FileReader(fileName));
Do not use FileReader. Instead, use a FileInputStream and an
InputStreamReader, specifying the correct encoding when you create the
InputStreamReader.
This is assuming you know the correct encoding. To answer the OP's
earlier question:
"Daniel Moyne" <dmoyne@tiscali.fr> wrote in message
news:erbs6k$7jc$1@news.tiscali.fr...
(b) when with a Java app you read a text file can you get its encoding
format like utf-8 or ANSI or whatever to decide about some actions to be
taken ?
No, you can't. No computer program possibly can, as it's often
ambiguous. The string "#HEADER" encoded in ASCII produces the exact same
sequence of bits as when it's encoded in UTF-8, for example. So given that
sequence of bits, it's impossible to know whether it was encoded in ASCII or
in UTF-8 -- the results are the same!
Possible solutions include: mandating a specific encoding (e.g. everyone
who uses your program must use UTF-8) or allowing the user to specify the
encoding (perhaps via command line arguments?)
- Oliver