Hi, I am trying to write a program having file handling. In it, I write an object in a .dat file. Is there any mechanism to read a specific object from a file? Is there any method like 'fseek()' as provided in C?
You can read/write a RandomAccessFile using your own code to convert your objects to/from bytes of data.
You can use Java ObjectOutputStream / ObjectInputStream to write/read simple or complex objects (including arrays & collections) with a single statement.
You can use XMLEncoder /XMLDecoder to encode/decode simple or complex objects (including arrays & collections) as XML text that you can write/read to file.
ps Classes (names starting with a capital letter) above are fully documented in the JAVA API doc.
The reference to fseek leads me to suspect a scenario where objects are written as fixed-length records, so it would be possible to use the java.io.RandomAccessFile seek(pos) method to seek directly to (record number)*(record length). Although I wouldn't recommend that kind of low-level approach unless the file size is humongous.