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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:41:37+00:00 2026-05-13T13:41:37+00:00

I have a text editor that uses code almost identical to the below for

  • 0

I have a text editor that uses code almost identical to the below for reading and writing. When I open small files for editting, I always get this error when I try to save them again. The really interesting thing though is that my text editor works fine for files with about 600 bytes or more (seems to vary each time), behaviour that I haven’t been able to replicate here.

My current workaround is to check for file size < 1024 bytes, and use java.io if that’s the case.

import java.io.*;
import java.nio.*;
import java.nio.channels.*;
import java.nio.charset.*;

public class Test {
    public static void main(String[] args) {
        String text = null;
        try {
            FileInputStream fis = new FileInputStream("test.txt");
            FileChannel ifc = fis.getChannel();
            CharBuffer cb = Charset.forName("ISO-8859-15").newDecoder().
                    decode(ifc.map(FileChannel.MapMode.READ_ONLY, 0,
                    (int) ifc.size()));
            text = cb.toString();
            ifc.close();
            fis.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        try {
            FileOutputStream fos = new FileOutputStream("test.txt");
            OutputStreamWriter osw = new OutputStreamWriter(
                    fos, "ISO-8859-15");
            osw.write(text);
            osw.close();
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

For the above code, I get this error for various sizes of test.txt from 4 bytes to 10kb:

java.io.FileNotFoundException: test.txt (The requested operation cannot be perfo
rmed on a file with a user-mapped section open)
        at java.io.FileOutputStream.open(Native Method)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at java.io.FileOutputStream.<init>(Unknown Source)
        at Test.main(Test.java:23)

Can anyone explain what I’m doing wrong and how I can get this to work while still reading with nio?

  • 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-05-13T13:41:37+00:00Added an answer on May 13, 2026 at 1:41 pm

    Stephen C told you to unmap the buffer.

    However, here is a link to STILL OPEN ( from 2002 ) request for MappedBybeBuffer.unmap method.

    It has a few workarounds suggested, so you may try them.

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

Sidebar

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.