其他分享
首页 > 其他分享> > 解决FileReader读取文本文件中字乱码问题

解决FileReader读取文本文件中字乱码问题

作者:互联网

String pathname = "web/static/outPutFile.txt"; 
FileReader reader = new FileReader(pathname);
BufferedReader br = new BufferedReader(reader);

原因:编码和解码的方式不一致导致乱码

解决方法一:将txt文件的编码方式设置为UTF-8.

解决方法二:使用转换流InputStreamReader,并设置解码方式为GBK

String pathname = "web/static/outPutFile.txt";
FileInputStream fis= new FileInputStream(new File(pathname));
InputStreamReader isr=new InputStreamReader(fis,"GBK");
BufferedReader br = new BufferedReader(isr);

标签:FileReader,BufferedReader,乱码,中字,pathname,new,txt,InputStreamReader
来源: https://blog.csdn.net/m0_56316453/article/details/119087879