文件显示问题
想要在控制台中打印 记事本中的内容 记事本中的内容是 "gyugf屌丝你好gjhgh"
打印出来的结果是"?gyugf屌丝你好gjhgh" 多出来了一个 ?号.
记事本的编码格式改成了 utf-8
代码如下:
File file =new File("E:/1234.txt");
byte []Byte=new byte[(int)file.length()];
FileInputStream in=new FileInputStream(file);
in.read(Byte);
String s=new String(Byte,"utf8");
System.out.println(s);
[最优解释]
文件前面有3个标志字节:0xef,0xbb,0xbf,跳国这3个字节就好了。
String s=new String(Byte,3,Byte.length-3,"utf8");//跳过前3 个字节