Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8895413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T23:46:21+00:00 2026-06-14T23:46:21+00:00

I have been tasked with creating a class (RandomAccessObjectFile) that provides reading and writing

  • 0

I have been tasked with creating a class (RandomAccessObjectFile) that provides reading and writing of objects as well as seeking within a file. This is my first time using Java File NIO and want to make sure I am grasping it correctly. Below are the methods I am required to have in the class and am looking for some help and more understanding on how to approach the rest of this class.

public class RandomAccessObjectFile {

RandomAccessFile raFile;
private RandomAccessObjectFile(String fileName) throws FileNotFoundException {
    raFile = new RandomAccessFile(new File(fileName), "rw");
}

static void create(String fileName) throws IOException {
    Path createTarget = Paths.get(fileName);
    Files.createFile(createTarget);
}

static void delete(String fileName) throws IOException {
    Path deleteTarget = Paths.get(fileName);
    Files.delete(deleteTarget);
}

static RandomAccessObjectFile open(String fileName) {

}

<T> void write(T obj) {
}

<T> T read() {

}

void seek(long location) {
}

long length() {

}

}

Thanks ahead of time for all of your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T23:46:23+00:00Added an answer on June 14, 2026 at 11:46 pm

    For background on the java.nio package you could start with the java tutorial.
    To serialize an object to a File, I’ve used ObjectOutputStream with good success.
    I think you may need some further clarification on what the seek method should do. Is the long input a File location? That seems like an odd thing to do since Objects written to the file will occupy various amounts of room in the file. Most inputs values to the seek method would be invalid since a particular location in the file may not represent the beginning of an object serialization. But if this is how the input parameter should be interpreted, then I think the method should throw an IllegalArgumentException if the input value does not represent the start of an Object.

    How will a user of this class know how to seek a particular Object?

    Maybe you should also store some index data. Maybe each object written to the file needs to have some unique ID field. Then create a map that maps these IDs to positions in the file. This map can then be used to quickly jump to the correct file location to read data. This approach should work well as long as the data in the file does not need to change. Adding new Objects to the file this way should work fine, but modifying an object or deleting one from the middle of the file would require more work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to WIX and have been tasked with creating an installer that
Recently I have been tasked with creating an application for a business that basically
I'm new to visual basic and have been tasked with creating an app that
I have been tasked with creating a service that will be consumed by jQuery
I have been tasked with creating a SQL query (limited knowledge) that will show
I have been tasked with creating a program that will generate an amortization schedule.
I have been tasked with creating a site wide search feature. The search needs
I have been tasked with refactoring some components that used xmlbeans to now make
I have been tasked with writing an installer with a silverlight out of browser
I have been tasked with creating a Software Installation Approval section for our Intranet.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.