import java.io.IOException;
import java.io.RandomAccessFile;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.junit.Test;
public class TestRandomAccessFile {
@Test
public void test() {
String file = "D:\\TestJava.txt";
String LineSeparator = System.getProperty("line.separator");
RandomAccessFile out;
try {
out = new RandomAccessFile(file, "rw");
out.seek(out.length());
if (out.getFilePointer() != 0) {
out.write(LineSeparator.getBytes());
}
if (null != out) {
Calendar cal = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
out.write(("Time:" + sdf.format(cal.getTime()) + " ")
.getBytes());
}
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}