如何用JavaScript检测文件是否采用UTF-8编码?
- 内容介绍
- 文章标签
- 相关推荐
本文共计615个文字,预计阅读时间需要3分钟。
javascriptconst isUtf8=async (file: File)=> { const reader=new FileReader(); reader.onload=function(e) { const text=e.target.result; const buffer=new TextEncoder().encode(text); const bytes=new Uint8Array(buffer); let isUtf8=true; for (let i=0; i 使用FileReader以utf-8格式读取文件,根据文件内容是否包含乱码字符�,来判断文件是否为utf-8。 如果存在�,即文件编码非utf-8,反之为utf-8。常规方案
本文共计615个文字,预计阅读时间需要3分钟。
javascriptconst isUtf8=async (file: File)=> { const reader=new FileReader(); reader.onload=function(e) { const text=e.target.result; const buffer=new TextEncoder().encode(text); const bytes=new Uint8Array(buffer); let isUtf8=true; for (let i=0; i 使用FileReader以utf-8格式读取文件,根据文件内容是否包含乱码字符�,来判断文件是否为utf-8。 如果存在�,即文件编码非utf-8,反之为utf-8。常规方案

