try { RandomAccessFile file = new RandomAccessFile("file.txt", "rw"); FileDescriptor fdObj = file.getFD(); // perform operations on the file using the file descriptor object file.close(); } catch (IOException e) { e.printStackTrace(); }
try { RandomAccessFile file = new RandomAccessFile("file.txt", "rw"); FileDescriptor fdObj = file.getFD(); // move file pointer to position 100 fdObj.seek(100); // write data to the file from the new position file.write("Hello, World!".getBytes()); file.close(); } catch (IOException e) { e.printStackTrace(); }This code retrieves the file descriptor object and uses its seek() method to move the file pointer to a new position (100). The write() method is then used to write data to the file from the new position. The examples use the java.io package library.