导包。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 就是所有读取内容。