Archive for the 'encoding' Category

22
Aug
11

ruby convert between encodings


In Ruby 1.8.7, you can convert like this:


require "kconv"
# line, destination encoding, source encoding
Kconv.kconv(line,NKF::UTF8,NKF::UTF16)

05
Aug
11

convert encodings using iconv


Here’s how you can use iconv to convert between encodings:


iconv --from-code=utf-16le --to-code=utf-8 some_file

11
Jan
10

SAXException: Invalid byte 2 of 2-byte UTF-8 sequence


If you ever receive this exception: SAXException: Invalid byte 2 of 2-byte UTF-8 sequence, then it means that the XML file you’re trying to read wasn’t encoded in UTF-8. If by any chance,you’re creating that XML, make sure you use the proper encoding when writing the file ( in this case UTF-8 ).

06
Jan
10

reading a text file with a certain encoding


Small snippet:


BufferedReader in = new BufferedReader(new InputStreamReader(stream, encoding)); // encoding is a string, like UTF-8




Blog Stats

  • 218,326 hits