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 8248641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:15:28+00:00 2026-06-07T23:15:28+00:00

I am reading a integer file using : int len = (int)(new File(file).length()); FileInputStream

  • 0

I am reading a integer file using :

int len = (int)(new File(file).length());
FileInputStream fis = new FileInputStream(file);
byte buf[] = new byte[len];
fis.read(buf);
IntBuffer up = ByteBuffer.wrap(buf).order(ByteOrder.LITTLE_ENDIAN).asIntBuffer();

But, it creates two copies of file in memory, 1) Byte Array copy 2) IntBuffer copy.

Is it possible to use the code in such a way thus it will create only one copy in memory?

  • 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-07T23:15:29+00:00Added an answer on June 7, 2026 at 11:15 pm

    The javadocs and the implementation from Oracle that I’ve looked at indicate that what you are saying is not true. The javadocs say that:

    public static ByteBuffer wrap(byte[] array)

    Wraps a byte array into a buffer.

    The new buffer will be backed by the given byte array; that is, modifications to the buffer will cause the array to be modified and vice versa.

    The code shows that the array passed into ByteBuffer.wrap is simply assigned as the internal array of the ByteBuffer. The ByteBuffer.asIntBuffer method simply shows the creation of an IntBuffer that uses the ByteBuffer.

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

Sidebar

Related Questions

I'm reading in binary files normally using: //What I use to read in the
I am reading a text file representing a maze pattern. each line is read
I am working on a program that requires reading in integers from a file
I am reading a huge number of Integers from a file, and at the
I keep reading that in order for one to perform integer/floating point division on
The code below is reading 4 bytes from a socket into an integer. I
I'm reading 16-bit integers from a piece of hardware over the serial port. Using
i am reading the bytes from binary file and now i have to get
So I'm reading in a file (like java program < trace.dat) which looks something
I managed to parse a large binary file (~8Gb) by reading blocks of data

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.