Idear中的乱码问题
编码和解码的编码表要一致
public static void main(String[] args) throws IOException {
String s = "啦啦啦";
// 编码:把字符串转换成为字节数组
byte[] bytes = s.getBytes("gbk");
// 解码:
//String(byte[] bytes, Charset charset)通过使用指定的 charset 解码指定的 byte 数组,构造一个新的 String
String s1 = new String(bytes,"gbk");
System.out.println(s1);
}
public static void main(String[] args) throws IOException {
InputStream is = new FileInputStream("c:\\bb\\a.txt");
//转换成字符流---转换流InputStreamReader(InputStream in, Charset cs) 创建使用给定字符集的 InputStreamReader。
InputStreamReader isr = new InputStreamReader(is,"gbk");
// 转换成高效流
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
System.out.println(s);
}