Java 中识别字符串编码
Java 大约 805 字添加依赖
<dependency>
<groupId>com.googlecode.juniversalchardet</groupId>
<artifactId>juniversalchardet</artifactId>
<version>1.0.3</version>
</dependency>
代码
public static void main(String[] args) {
// byte[] body = "汉字".getBytes(StandardCharsets.UTF_8);
byte[] body = "汉字".getBytes(Charset.forName("GB2312"));
UniversalDetector detector = new UniversalDetector(null);
detector.handleData(body, 0, body.length);
detector.dataEnd();
String encoding = detector.getDetectedCharset();
if (encoding != null) {
System.out.println("Detected encoding = " + encoding);
} else {
System.out.println("No encoding detected.");
}
detector.reset();
}
文档
阅读 2085 · 发布于 2020-09-25
————        END        ————
Give me a Star, Thanks:)
https://github.com/fendoudebb扫描下方二维码关注公众号和小程序↓↓↓

昵称:
随便看看
换一批
-
PostgreSQL 生成 XML 网站地址阅读 2348
-
Java 中的序列化 Serializable 和 Externalizable阅读 1709
-
Go JSON 的序列化和反序列化阅读 3940
-
Linux 文件删除后未释放空间解决办法阅读 2329
-
PHP 生成重复固定随机数邀请码阅读 2826
-
软考-系统架构设计师:存储管理-段页式存储组织阅读 4062
-
Kubernetes Pod 控制器 Deployment阅读 1000
-
Android 一键清理用户数据阅读 2779
-
Spring 事务失效的几种场景阅读 1485
-
Spring Boot 修改 RestTemplate 默认编码格式阅读 7354