我单独测试了一下一个汉字的gbk编码,为什么测出来长度是三,不应该是2吗
package com.imooc.io; import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import sun.font.CreatedFontTracker; public class RafDemo { /** * @param args * @throws IOException */ public static void main(String[] args) throws IOException { // TODO Auto-generated method stub File demo=new File("demo"); if(!demo.exists()){ demo.mkdir(); } File file=new File(demo,"raf.dat"); if(!file.exists()){ file.createNewFile(); } RandomAccessFile raf=new RandomAccessFile(file, "rw"); String s="中 "; byte[] gbk=s.getBytes("gbk"); raf.write(gbk); System.out.println("指针的位置:"+raf.getFilePointer()); System.out.println("长度:"+raf.length()); } }