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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:36:01+00:00 2026-06-10T22:36:01+00:00

I am getting IOException: Map Failed when trying to write a large byte array.

  • 0

I am getting IOException: Map Failed when trying to write a large byte array. I use the method below to write a byte array to a file

private static void write(byte[] data) throws Exception {
        File file = new File("C:/temp/file.json");
        int length = data.length;
        RandomAccessFile raf = new RandomAccessFile(file, "rw");
        FileChannel fc = raf.getChannel();
        MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_WRITE, 0, length);
        for (int i = 0; i < length; i++) {
            buffer.put(data[i]);
        }
}

The byte array is about 270mb.
Can anyone explain what I am doing wrong?
Thanks.

  • 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-10T22:36:02+00:00Added an answer on June 10, 2026 at 10:36 pm

    I am not sure why the map failed, but I wouldn’t do it the way you have done.

    FileOutputStream out = new FileOutputStream(filename);
    out.write(data);
    out.close();
    

    to do it progressively you can use

    FileOutputStream out = new FileOutputStream(filename);
    for(int i = 0; i < data.length; i += 8192)
        out.write(data, i, Math.min(data.length-i, 8192));
    out.close();
    

    The map could fail if you have a 32-bit JVM and you call this method repeatedly. e.g. you run out of virtual memory.

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

Sidebar

Related Questions

When trying get in memcache client, getting the below excepton. Caused by: java.io.IOException: com.fet.myclass.webservice.data.DataList
Getting extremely confused with an adminhtml module i'm trying to write! Effectively I have
Getting 401 errors when trying to use ASP.NET back end in load balanced environment
I am getting java.lang.VerifyError.I am posting my log-file and code below. I have looked
I keep getting this error 07-28 19:32:40.536: ERROR/error(534): java.io.IOException: No such file or directory
I'm getting: java.io.IOException: Invalid header signature; read 0x000201060000FFFE, expected 0xE11AB1A1E011CFD0 when trying to add
I am use OpenHttpConnection(URL) method to connect internet in my android application. But getting
Getting message expected identifier in red for below these two statements } else if
Getting ERR_CONNECTION_RESET after more or less 2 minutes of uploading a rather big file
Getting 'Dispatcher has no subscribers' error while trying to post message to a channel

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.