Re: How to specify encoding in Java?

From: Raymond DeCampo (rdecampo_at_spam-I-am-not.twcny.rr.com)
Date: 01/25/04


Date: Sun, 25 Jan 2004 03:08:51 GMT

Konrad Den Ende wrote:
> I've been looking around and i've been given some hints but
> i simply can't get to the bottom of it. How do i specify the
> character encoding for reading text froma file?
>

Open the file as normal with an InputStream. Then use InputStreamReader
to wrap the stream, passing the desired encoding.

E.g., to open a file in UTF-16:

InputStream is = new BufferedInputStream(
        new FileInputStream("unicode.txt"));
Reader reader = new InputStreamReader(is, "UTF-16");

See the javadoc for more information on which encodings are supported
and fancier ways of specifying them.

Ray



Relevant Pages

  • Re: Data source not "sticking"
    ... First, as far as I am aware, when the data source is a text file and you ... have to specify the encoding, Word does not store the information about the ... encoding when it saves the mail merge main document. ... XML format (i.e. not the sort of simple XML format doucment you might ...
    (microsoft.public.word.docmanagement)
  • Re: Uniquely identifying Sudoku grids
    ... |> uniquely specify every possible sudoku. ... |So you'd need 22 digits to uniquely specify a sudoku puzzle. ... deck of 52 cards +2 jokers, how many poker hands are ... or some such encoding that can be easily ...
    (rec.puzzles)
  • Re: =?UTF-8?B?77u/V2hlbg==?= X.ZIP downLoads a post or eMail, Windows-1252 is the default.
    ... It's very common for a newsReader to specify ISO-8859-1 ... doesn't fit into the ISO standards. ... | When a user agent would otherwise use an encoding given in the ... mis-identified as using ISO standard character encodings. ...
    (news.software.readers)
  • Re: Print Spanish characters in Perl?
    ... and ensure that your file is saved in the UTF-8 format. ... encoding then your display device expects. ... forgetting to specify UTF-8 as charset. ... To avoid this kind of problem, make sure that all the characters are ...
    (comp.lang.perl.misc)
  • Re: Why doesnt strrstr() exist?
    ... > Unicode is a character set, not an encoding. ... > AFAIK the language doesn't specify how to deal with Unicode ... I am not *that* familliar with Java. ...
    (comp.lang.c)