java 文件io学习笔记

1 使用file reader测试随机io时间。

实验非预期结果:

a 当我修改了small.txt文件内容时,下一个循环依然是旧的内容,new,read操作读的是缓存??

b 当只执行一次read操作时,执行时间不足1ms,比想象中的快。据说磁盘寻道时间平均是8ms??

基本上可以判断为是操作系统内核预读、内核缓存的结果

http://www.iteye.com/problems/80027

此文是很好的参考

http://tech.fuwuqi.com.cn/Servertn/operatings/2009-10-27/5660986715653.shtml

 

@Test
	public void testSeek() throws IOException {
		int num = 100;
		char[] cbuf = new char[12 * 10];
		long start = System.currentTimeMillis();
		for (int i = 0; i < num; i++) {
			FileReader fr = new FileReader("small.txt");
			// System.out.println(System.currentTimeMillis() - start);

			fr.read(cbuf);
			fr.close();

			System.out.println(new String(cbuf).toString());

		}

		System.out.println(System.currentTimeMillis() - start);

	}
 

相关引用:

http://www.uml.org.cn/zjjs/201006121.asp

http://qxavier.info/2011/03/31/java-memory-mapped-file-stream-and-the-i-o-performance-comparison/

你可能感兴趣的:(java,IO,File)