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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:42:17+00:00 2026-06-14T11:42:17+00:00

I have the code below, which simply reads all the files from a folder.

  • 0

I have the code below, which simply reads all the files from a folder. There are 20,000 files in this folder. The code works good on a local folder (d:/files), but fails on a network path (//robot/files) after reading about 1,000 – 2,000 files.

Update: the folders are copies of each other.

What causes this problem and how to fix it?

package cef_debug;

import java.io.*;

public class Main {

    public static void main(String[] args) throws Throwable {
        String folder = args[0];
        File[] files = (new File(folder)).listFiles();
        String line;
        for (int i = 0; i < files.length; i++) {
            BufferedReader br = new BufferedReader(new FileReader(files[i]));
            while ((line = br.readLine()) != null) {
            }
            br.close();
        }
    }
}

I get the following error when reading from a network path (//robot/files):

Exception in thread "main" java.io.IOException: Too many open files
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:106)
        at java.io.FileReader.<init>(FileReader.java:55)
        at cef_debug.Main.main(Main.java:12)
Java Result: 1

Line 12 is the line:

BufferedReader br = new BufferedReader(new FileReader(files[i]));
  • 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-14T11:42:19+00:00Added an answer on June 14, 2026 at 11:42 am

    There is a documented bug for some java versions and some file opens to hit a limit of 2035. It is possible that you might’ve just hit that.

    From the comments:

    To clarify the issue, on win32 system there are three ways to open a
    file:

    1: Using Win32 API

    2: Using MFC class framework lib.

    3: using C-Library API (open() and fopen())

    Other than the third option, i.e. option 1 and 2 have practically no
    limitation in opening number of files. The third method is restricted
    (for the reason not known to me) to open only approx. 2035 files. That
    is why MS JVM is able to open unlimited (practically) files, but SUN
    JVM fails after 2035 files (my guess is it is using 3rd method to
    open file).

    Now, this is an old issue fixed quite some time ago, but it is possible that they would be using the same function on network access, where the bug could still exist.

    Even without closing the handle or the stream, windows should be able to open >10000 file handles and keep them open, as demonstrated by this test code in the bug comments:

    import java.util.*;
    import java.io.*;
    
    // if run with "java maxfiles 10000", will create 10k files in the current folder
    public class maxfiles
    {
        static int count = 0;
        static List files = new ArrayList();
    
        public static void main(String args[]) throws Exception
        {
            for (int n = 0; n < Integer.parseInt(args[0]); n++) {
                File f = new File("file" + count++);
                //save ref, so not gc'ed
                files.add(new PrintStream(new FileOutputStream(f)));
            }
            Iterator it = files.iterator();
            while (it.hasNext()) {
                PrintStream out = ( PrintStream) it.next();
                out.println("foo");
                out.flush();
            }
            System.out.println("current files open: " + files.size());
        } //~main
    }
    

    You could test running it on the network share, and report a bug if it fails. You could also try with a different JDK. At least with OpenJDK source, I couldn’t see any other calls except WinAPI calls, so I’d try if the behaviour is the same.

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

Sidebar

Related Questions

I have a function(please see code below) which reads some data from the web.
I have a piece of matlab code below which reads data from a table.
I have the following code below which works, but I want to insert values
I have wrote the code below which was taken from Java How to program
I have the code below, which works fine it can be viewed for an
I have a curl script which reads the data from a remote source. Below
I have the code below which I use clone() and live() . The code
I have the code below which I use clone() and delegate() . The code
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)
I have a working JavaScript code below which dynamically creates JSON object using JSON.parse

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.