⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testobjectfile.java

📁 国外的数据结构与算法分析用书
💻 JAVA
字号:
import dslib.file.ObjectFileUos;

public class TestObjectFile
{
	/**	Show how sequential access to objects in a file can be
		achieved by using the ObjectFileUos class */
	TestObjectFile()
	{

		ObjectFileUos of = new ObjectFileUos("testObjFile","rw");
		long pos1, pos2, pos3, pos4;
		/* write the "records" to disk sequentially */
		pos1 = of.position();
		of.writeObject(new Integer(999));
		pos2 = of.position();
       		of.writeObject(new Double(555));
		pos3 = of.position();
		of.writeObject(new Integer(23));
		pos4 = of.position();
		of.writeObject(new Integer(523));

		/* close the file */
		of.close();

		/* open the file again */
		of.openFile("testObjFile","rw");
		/* read in the records sequentially */
		Object last;
		while (!of.eof())
		{
			last = of.readObject();
			System.out.println("Last record read: " + last);
		}
		last = of.readObjectFrom(pos1);
		System.out.println("Trying to read 999: " + last);
		last = of.readObjectFrom(pos2);
		System.out.println("Trying to read 555: " + last);
		last = of.readObjectFrom(pos3);
		System.out.println("Trying to read 23: " + last);
		last = of.readObjectFrom(pos4);
		System.out.println("Trying to read 523: " + last);
		System.out.println("Rewriting 23 as 32");
		of.writeObjectAt(new Integer(32), pos3);
		last = of.readObjectFrom(pos3);
		System.out.println("Trying to read 32: " + last);
		/* close the file */
		of.close();
	}

	public static void main(String[] args)
	{
		TestObjectFile tof = new TestObjectFile();
	}
}




⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -