关于怎么知道上传文件是什么类型的编码上面文章有做代码块。
我项目测试中 遇到这样可以通过 流的读取时候才不会有乱码:
if (charset=="GBK") { //GBK编码 or GB2312编码
System.out.println("charset:"+charset);
InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(filepath)),"GBK");
br = new BufferedReader(reader);
}
if (charset=="UTF-8") { //UTF-8编码
System.out.println("charset:"+charset);
br=new BufferedReader(new InputStreamReader(new FileInputStream(filepath),"UTF-8"));
}
我项目测试中 遇到这样可以通过 流的读取时候才不会有乱码:
if (charset=="GBK") { //GBK编码 or GB2312编码
System.out.println("charset:"+charset);
InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(filepath)),"GBK");
br = new BufferedReader(reader);
}
if (charset=="UTF-8") { //UTF-8编码
System.out.println("charset:"+charset);
br=new BufferedReader(new InputStreamReader(new FileInputStream(filepath),"UTF-8"));
}