2025-08-08 18:24:27 德国世界杯预选赛

编码工具类EncodingUtils(解决乱码问题)

原文连接 http://www.apihome.cn/api/android/EncodingUtils.html

org.apache.http.util 类 EncodingUtils java.lang.Object org.apache.http.util.EncodingUtils

public final class EncodingUtilsextends Object

The home for utility methods that handle various encoding tasks.

从以下版本开始:4.0作者:Michael Becke, Oleg Kalnichevski

方法摘要

static byte[]getAsciiBytes(String data) Converts the specified string to byte array of ASCII characters. static StringgetAsciiString(byte[] data) Converts the byte array of ASCII characters to a string. static StringgetAsciiString(byte[] data, int offset, int length) Converts the byte array of ASCII characters to a string. static byte[]getBytes(String data, String charset) Converts the specified string to a byte array. static StringgetString(byte[] data, int offset, int length, String charset) Converts the byte array of HTTP content characters to a string. static StringgetString(byte[] data, String charset) Converts the byte array of HTTP content characters to a string.

从类 java.lang.Object 继承的方法

equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

方法详细信息

getString public static String getString(byte[] data, int offset, int length, String charset) Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.

参数:data - the byte array to be encodedoffset - the index of the first byte to encodelength - the number of bytes to encodecharset - the desired character encoding返回:The result of the conversion.

getString public static String getString(byte[] data, String charset) Converts the byte array of HTTP content characters to a string. If the specified charset is not supported, default system encoding is used.

参数:data - the byte array to be encodedcharset - the desired character encoding返回:The result of the conversion.

getBytes public static byte[] getBytes(String data, String charset) Converts the specified string to a byte array. If the charset is not supported the default system charset is used.

参数:data - the string to be encodedcharset - the desired character encoding返回:The resulting byte array.

getAsciiBytes public static byte[] getAsciiBytes(String data) Converts the specified string to byte array of ASCII characters.

参数:data - the string to be encoded返回:The string as a byte array.

getAsciiString public static String getAsciiString(byte[] data, int offset, int length) Converts the byte array of ASCII characters to a string. This method is to be used when decoding content of HTTP elements (such as response headers)

参数:data - the byte array to be encodedoffset - the index of the first byte to encodelength - the number of bytes to encode返回:The string representation of the byte array

getAsciiString public static String getAsciiString(byte[] data) Converts the byte array of ASCII characters to a string. This method isto be used when decoding content of HTTP elements (such as responseheaders) 参数:data - the byte array to be encoded返回:The string representation of the byte array

《原神》稻妻宝箱位置图文汇总 稻妻隐藏宝箱有哪些?
手机导航哪个好用?为你推荐几款优秀的手机导航应用
top