fun code(ins: InputStream): String {
val head = ByteArray(3)
ins.read(head)
return when {
(head[0].toInt() == -1 && head[1].toInt() == -2) -> "UTF-16"
(head[0].toInt() == -2 && head[1].toInt() == -1) -> "Unicode"
(head[0].toInt() == -17 && head[1].toInt() == -69 && head[2].toInt() == -65) -> "UTF-8"
else -> "GBK"
}
}
kotlin 判断文件编码
最新推荐文章于 2023-02-24 09:35:26 发布