尧图网络科技YAOTU DIGITAL 获取报价
获取报价
首页 / 资讯中心 / 文章详情

java获取文件编码格式,然后读取此文件,适用于任何格式的文件。

发布时间:2026/9/18 16:56:20

资讯中心
01
ARTICLE

java获取文件编码格式,然后读取此文件,适用于任何格式的文件。

java获取文件编码格式,然后读取此文件,适用于任何格式的文件。
导包。dependency groupIdcom.googlecode.juniversalchardet/groupId artifactIdjuniversalchardet/artifactId version1.0.3/version /dependency写方法public static String detect(String path) throws IOException { UniversalDetector detector new UniversalDetector(null); try (InputStream is new FileInputStream(path)) { byte[] buf new byte[4096]; int len; while ((len is.read(buf)) 0 !detector.isDone()) { detector.handleData(buf, 0, len); } } detector.dataEnd(); String encoding detector.getDetectedCharset(); detector.reset(); return encoding; }调用String filePath path; String fileEncoding detect(filePath);根据读取的编码读取文件ListString lines null; lines Files.readAllLines(Paths.get(filePath), Charset.forName(fileEncoding ));lines 就是所有读取内容。
02
RELATED NEWS

相关资讯

更多网站建设与数字化升级内容

03
WHY YAOTU

想打造同款高转化官网?

懂行业、懂生意,从建站到增长一站式陪跑

场景化定制

不做模板站,围绕你的业务场景量身设计,小众不撞款。

营销型架构

以转化目标组织内容与路径,让官网真正带来询盘。

全周期服务

设计、开发、运营、运维一体,上线只是开始。

免费获取你的建站方案

留下需求,专属顾问 24 小时内为你输出方案建议。