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.
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...