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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:17:43+00:00 2026-06-02T23:17:43+00:00

I in the process of writting a simple java program which reads the contents

  • 0

I in the process of writting a simple java program which reads the contents of the directory
and print out the names of the files and last modified time .

The issue i forsee is , the vault i am reading is pretty huge and there are some case where
the files in a single directory can well exceed 20000.
Using file api

    `file.listFiles()` 

would inturn create 20000 file objects, my concern this
could slow down the process , may be bloat the memory as well.

Is there a way to batch i.e to tell java to scan the directory in terms of 50 files at a time or atleast iterate one file at a time instead of loading all objects in memory at once

  • 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-02T23:17:44+00:00Added an answer on June 2, 2026 at 11:17 pm

    You should use a java.nio.file.FileVisitor via java.nio.file.Files.walkFileTree(…). It has been introduced in Java 7 exactly for this use case.

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

Sidebar

Related Questions

I am writing a java program in eclipse(galileo version). The program reads simple user
Let's say you had an external process writing files to some directory, and you
I'm writing a simple program that reads and processes file content using a BufferedReader
I am writing simple webapp in Java (for educational purpuses only) which allows admin
I am writing a cross-platform program which requires simple information on the running program:
Is this a simple process? I'm only writing a quick hacky UI for an
Overview I'm in the process of porting a simple utility app over from C#
I'm in the process of writing a simple console app that monitors a particular
I'm currently writing a simple multicaster module. Only one process can open a proc
While simple, interface-driven event notification frameworks in Java have been around since pre-Cambrian times

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.