开发者

Is there an equivalent to .NET's System.Text.Encoding in Java?

开发者 https://www.devze.com 2022-12-17 23:27 出处:网络
I\'m looking for an equivalent to .NET\'s System.Text.Encoding in Java. For example in C# I开发者_高级运维 can do this:

I'm looking for an equivalent to .NET's System.Text.Encoding in Java. For example in C# I开发者_高级运维 can do this:

Encoding defaultEncoding = Encoding.Default;
byte[] encoded = defaultEncoding.GetBytes("Text to encode");

I would like to be able to do the same in Java.


The java string object has encoding support. getBytes() takes an argument of encoding type. Addendum: Oh and by the way, myStringVar.getBytes() will return platform default encoding of the bytes.

String myStringVar = "Text to get bytes for";
byte[] textBytes = myStringVar.getBytes("UTF-8");
0

精彩评论

暂无评论...
验证码 换一张
取 消