假设不是约定好的,要想解析txt文件就须要知道文件编码类型,因为文件编码类型众多。比如UTF-8,GBK。UTF-16,GB2312等等。
事实上有简单的办法。仅仅须要这样就能够了
String fileEncode=EncodingDetect.getJavaEncode(filePath);
String fileContent=FileUtils.readFileToString(new File(filePath),fileEncode);
引用commons-io-2.4.jar就可以
http://mvnrepository.com/artifact/commons-io/commons-io/2.4
maven
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
直接下载:http://central.maven.org/maven2/commons-io/commons-io/2.4/commons-io-2.4.jar
EncodingDetect.java
http://download.csdn.net/detail/21aspnet/9423476