Java encoding

I have a C # function that I want to translate into Java code. I have a problem:

Encoding enc = Encoding.GetEncoding("Windows-1252");

bytZeichenBenutzer = enc.GetBytes(strBenutzer.Substring(intLoopCount, 1).ToCharArray());

How to do it in Java? I can not find anything similar only to material that works with UTF-8.

+3
source share
3 answers

You can use getBytes(String)either getBytes(Charset)methods:

String myString = getMyStringFromSomeWhere();
byte[] utf8Bytes = myString.getBytes("UTF-8");
// or
Charset myCharset = Charset.forName("Windows-1252");
byte[] windowsBytes = myString.getBytes(myCharset);
+5
source
String s = "hhh"; 
try {   
  s.getBytes("Windows-1252"); 
} catch(UnsupportedEncodingException e) { 
  e.printStackTrace();  
}
0
source

You can do:

byte[] a = "some string".getBytes("Windows-1252");
0
source

All Articles