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

  • Home
  • SEARCH
  • 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 58661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T17:52:58+00:00 2026-05-10T17:52:58+00:00

I have the following fields: Inventory control (16 byte record) Product ID code (int

  • 0

I have the following fields:

  • Inventory control (16 byte record)
    • Product ID code (int – 4 bytes)
    • Quantity in stock (int – 4 bytes)
    • Price (double – 8 bytes)

How do I create a fixed length random access file using the above lengths? I tried some examples online, but I either get an EOF exception or random address values when I try to access them.

I tried some more examples and couldn’t understand the concept very well. I’m trying a project with it and will try to explore more on it.

Here is some example data. There might be holes in the data where No. in stock could be 23 == 023.

          Quantity ID. No.   In Stock   Price  -------   --------   ------  1001       476      $28.35  1002       240      $32.56  1003       517      $51.27  1004       284      $23.75  1005       165      $32.25 

Thanks for the 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. 2026-05-10T17:52:59+00:00Added an answer on May 10, 2026 at 5:52 pm

    java.io.RandomAccessFile is the class you’re looking for. Here’s an example implementation (you’ll probably want to write some unit tests, as I haven’t 🙂

    package test;  import java.io.IOException; import java.io.RandomAccessFile;  public class Raf {     private static class Record{         private final double price;         private final int id;         private final int stock;          public Record(int id, int stock, double price){             this.id = id;             this.stock = stock;             this.price = price;         }          public void pack(int n, int offset, byte[] array){             array[offset + 0] = (byte)(n & 0xff);             array[offset + 1] = (byte)((n >> 8) & 0xff);             array[offset + 2] = (byte)((n >> 16) & 0xff);             array[offset + 3] = (byte)((n >> 24) & 0xff);         }          public void pack(double n, int offset, byte[] array){             long bytes = Double.doubleToRawLongBits(n);             pack((int) (bytes & 0xffffffff), offset, array);             pack((int) ((bytes >> 32) & 0xffffffff), offset + 4, array);         }          public byte[] getBytes() {             byte[] record = new byte[16];             pack(id, 0, record);             pack(stock, 4, record);             pack(price, 8, record);             return record;         }     }      private static final int RECORD_SIZE = 16;     private static final int N_RECORDS = 1024;      /**      * @param args      * @throws IOException       */     public static void main(String[] args) throws IOException {         RandomAccessFile raf = new RandomAccessFile(args[0], 'rw');         try{             raf.seek(RECORD_SIZE * N_RECORDS);              raf.seek(0);              raf.write(new Record(1001, 476, 28.35).getBytes());             raf.write(new Record(1002, 240, 32.56).getBytes());         } finally {             raf.close();         }     } } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 170k
  • Answers 170k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You could accomplish this in one query like this: SELECT… May 12, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer Sadly both official documentation from both vendors seem happy to… May 12, 2026 at 2:07 pm
  • Editorial Team
    Editorial Team added an answer Stateful Sessions are not always a good choice, sometimes using… May 12, 2026 at 2:07 pm

Related Questions

I had a huge file for creating this GUI and I have shortened it
Background: I am an intermediate web app developer working on the .Net Platform. Most
I'm running the following query on my database, which generates a sql query I
I have a table Orders with the following fields: Id | SubTotal | Tax

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.