Code example for RandomAccessFile

Methods: RandomAccessFile.write, close, write, writeInt

0
	public void demo1() throws IOException { 
		File file = new File(classPath + "test.txt");
		if (file.exists()) {
			file.delete();
		} 
		RandomAccessFile ranFile = new RandomAccessFile(file, "rw");
		String name = "张三";
		int age = 30  ;
		ranFile.write(name.getBytes("UTF-8"));
		ranFile.write(age);
		 
		name = "lisi    ";
		age = 40  ;
		ranFile.write(name.getBytes("UTF-8"));
		ranFile.writeInt(age);
		 
		name = "wangwu  ";
		age = 50  ;
		ranFile.write(name.getBytes("UTF-8"));
		ranFile.writeInt(age);
		 
		ranFile.close();
	} 
	 
	@Test 
	public void demo2() throws IOException { 
		File file = new File(classPath + "test.txt");