Skip to content

Conversation

@adaJQD
Copy link
Contributor

@adaJQD adaJQD commented Nov 24, 2019

No description provided.

@Blankj Blankj merged commit 272a8fb into Blankj:1.26.0 Nov 24, 2019
@Blankj
Copy link
Owner

Blankj commented Nov 24, 2019

如果是空文件 int code = bis.read(); 返回的直接就是 -1 了,你还进去判断没什么意义吧,导致空文件直接就是 false 了哦(虽然也没好办法解决)。
代码我是读懂了,根据 utf8 的格式来判断字节数,然后判断 1,0,我那段代码是参考这篇文章:https://blog.csdn.net/qyp199312/article/details/79501112
我觉得还是我之前的那种比较简洁明了哈。

@adaJQD
Copy link
Contributor Author

adaJQD commented Nov 25, 2019

都是需要遍历文件内容,然后根据 utf8 格式判断。就看哪个实现方式效率更高了。
但是你的有个问题,只判断了前24个字节

public static boolean isUtf8(final File file) {
        if (file == null) return false;
        InputStream is = null;
        try {
            byte[] bytes = new byte[24];
            ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants