原文链接:http://www.software8.co/wzjs/java/1185.html
public static String getTxtType(File file) throws IOException { // TODO Auto- generated method stub
InputStream inputStream=new FileInputStream(file);
byte []head=new byte[3];
inputStream.read(head);
String code="";
code="gb2312";
if(head[0]==-1&&head[1]==-2){
code="UTF-16";
}
if(head[0]==-2&&head[1]==-1){
code="Unicode";
}
if(head[0]==-17&&head[1]==-69){
code="UTF-8";
}
return code;
}