寻思很久未能解决的问题,关于char的读取
java吧
全部回复
仅看楼主
level 6
Zebe_32 楼主
看吧,生成的文件确实等于 2byte + 2byte + 1byte * 5 = 9 byte(字节),为什么读取就不行呢?
下图是写文件和读文件的代码,中文读出来是问号:
下图是生成的文件,文件大小吻合,刚好 9 字节:
2013年03月19日 04点03分 1
level 12
十五马?有机个咯和好处恩金昌不。
2013年03月19日 05点03分 2
这是哪国的语言?
2013年03月19日 05点03分
level 7
转一下编码格式
RandomAccessFile accessFile = new RandomAccessFile("dd", "rw");
String name = "中国china";
System.out.println(name);
byte[] bs = name.getBytes();
accessFile.write(bs);
RandomAccessFile accessFile2 = new RandomAccessFile("dd", "rw");
byte[] b1 = new byte[] { accessFile2.readByte(), accessFile2.readByte() };
String china = new String(b1, "gbk");
System.out.print(china);
byte[] b2 = new byte[] { accessFile2.readByte(), accessFile2.readByte() };
String china2 = new String(b2, "gbk");
System.out.print(china2);
转成gbk这样我的输出正常了
2013年03月19日 05点03分 3
你这个好难读
2013年03月19日 05点03分
回复 Zebe_32 :就是汉字的不读char读2个byte然后在转成字符串
2013年03月19日 06点03分
1