JAVA编码问题
public class Demo04 {
public static void main(String[] args) {
File f = new File("d:/JAVA/txt4.txt");
try {
FileInputStream fileInputStream = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
fileInputStream.read(b);
String str = new String(b, "UTF-8"); //把这个数字,放在UTF-8的棋盘上去:
System.out.println(str);//1、Java是什么2、到底能干什么?
String s = new String(b, "GBK");//把这个数字,放在GBK的棋盘上去:
System.out.println(s);//1銆丣ava鏄粈涔�2銆佸埌搴曡兘骞蹭粈涔堬紵 (乱码)
fileInputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}