2 - 3 : RandomAccessFile クラスサンプル

RandomAccessFile クラスの主にファイルポインタ移動メソッドのサンプル。

[RandomAccessFileTest.java]
import java.io.IOException;
import java.io.RandomAccessFile;

/**
* RandomAccessFile サンプル
*/
public class RandomAccessFileTest {

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

RandomAccessFile file = new RandomAccessFile(args[0], "rw");

// ファイルポインタを先頭へ
file.seek(0);

// ファイルポインタを末尾へ
file.seek(file.length());

file.close();
}
}