读取txt文件乱码:
BufferedReader read = new BufferedReader(new FileReader(new File(filename)));
解决办法:
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "UTF-8");
但是新的java中会报错,应该使用
InputStreamReader isr = new InputStreamReader(new FileInputStream(file),StandardCharsets.UTF_8);
BufferedReader read = new BufferedReader(isr);
因为InputStreamReader和BufferedReader都继承自Reader,而BufferedReader的构造器又是Reader.