Menu
  • HOME
  • TAGS

How can I convert byte CP-1252 to byte UTF-8 in java [duplicate]

java,utf-8,converter,typeconverter,cp1252

You should use "Cp1252" as code page instead of "CP-1252" public void convert(){ try { byte[] cp1252 = new byte[]{(byte) 0xB5}; byte[] utf8= new String(cp1252, "Cp1252").getBytes("UTF-8"); } catch (Exception ex) { System.out.println(ex.getMessage()); } } Java supported encodings As pointed out 0xB5 you are trying to decode is not code page...

Unmappable character for encoding Cp1252 when trying to compile Java program

java,cp1252

The issue is that you're using smart quotes instead of the actual quote character. Here's a 'fixed' version of your code: import acm.program.*; public class test extends Program { public void run() { println("Hello world!!!"); } } Note the difference between " and ”. To fix this (and it depends...

Java, Ant error: unmappable character for encoding Cp1252

java,encoding,ant,utf-8,cp1252

This can be tricky simply changing the "advertised" encoding does not make up for the fact that there are bytes in the file that cannot be understood using a UTF-8 interpretation. In Ant you will need to update the javac task to add an encoding like, <javac ... encoding="utf-8"> Make...

“Raw” conversion from double-UTF-8 to UTF-8 (or from UTF-8 to ANSI)

encoding,utf-8,character-encoding,iconv,cp1252

The following code uses the low-level encoding functions of Ruby to force the rewriting of double encoded UTF-8 (from CP1525) into normal UTF-8. #!/usr/bin/env ruby ec = Encoding::Converter.new(Encoding::UTF_8, Encoding::CP1252) prev_b = nil orig_bytes = STDIN.read.force_encoding(Encoding::BINARY).bytes.to_a real_utf8_bytes = "" real_utf8_bytes.force_encoding(Encoding::BINARY) orig_bytes.each_with_index do |b, i| b = b.chr situation = ec.primitive_convert(b.dup, real_utf8_bytes,...

allow UTF-8 encoded filenames on (file-)webserver?

url,encoding,utf-8,download,cp1252

You should be storing the files on disk using a randomly generated name, or let the file name be based on a hash of the file contents (good for deduplicating storage as well). You can save the original file name as meta data in a database together with all other...