Java 读取UTF-8文件中文乱码
InputStreamReader isr = new InputStreamReader(new FileInputStream(file), "UTF-8");
BufferedReader read = new BufferedReader(isr);
例如:
private static String readUTF8File(String filePath) throws IOException { InputStreamReader isr = null; BufferedReader read = null; StringBuffer str = null; try { isr = new InputStreamReader( new FileInputStream(new File(filePath)), "UTF-8"); read = new BufferedReader(isr); str = new StringBuffer(); char[] buff = new char[1024]; int byteRead = 0; while ((byteRead = read.read(buff)) != -1) { str.append(new String(buff, 0, byteRead)); } return str.toString(); } finally { isr.close(); read.close(); str = null; isr = null; read = null; } }
应该没问题,试试吧!