问答详情
源自:3-1 RandomAccessFile基本操作

raf.write报错

public class RadomAccessFileTest {

public static void main(String[] args) throws IOException {

File file = new File("C:\\Users/Administrator/Desktop/a.txt");

RandomAccessFile raf = new RandomAccessFile(file,"rw");

System.out.println(raf.getFilePointer());

raf.seek(raf.length());

raf.write("a");

}

}


提问者:qq_哭的狠丶低调_0 2017-09-20 13:15

个回答

  • 阿双otw
    2017-09-20 17:00:16

    RandomAccessFile 一次只能写一个字节,"a"是个字符串,可以换成'a'或者"a".getBytes();

    getBytes()方法可以设置编码类型如gbk,utf-8等