Code example for RandomAccessFile

Methods: length, seek, write

0
		myFile = new File(fileName);
	} 
 
	public void hearTelephone(String heardMess) {
		try { 
			RandomAccessFile out = new RandomAccessFile(myFile, "rw");
			out.seek(out.length());
			byte[] b = heardMess.getBytes();
			out.write(b); // 更新文件中的内容
			System.out.print("我是一个大学生,");
			System.out.println("我向文件" + myFile.getName() + "写入如下内容:");
			System.out.println(heardMess);
		} catch (IOException exp) {
			System.out.println(exp.toString());
		} 
	} 
}