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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T13:21:50+00:00 2026-06-07T13:21:50+00:00

I have been using a specific piece of code to delete files from a

  • 0

I have been using a specific piece of code to delete files from a folder but it is proving very problematic because maybe I forgot to close an InputStream or two. The code I have is so big that I am not be able to see all the Inputstreams that I have not closed. Is there a way of deleting files whether there is an open InputStream or not?

This is the piece of the code that I have been using;

File fin = new File("C:/ABC Statements final/");
    File[] finlist = fin.listFiles();       
    for (int n = 0; n < finlist.length; n++) {
        if (finlist[n].isFile()) {
        System.gc();
        Thread.sleep(2000);
            finlist[n].delete();
        }
    }        

I have edited the code. This version works.

  • 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-07T13:21:52+00:00Added an answer on June 7, 2026 at 1:21 pm

    There is no InputStream instances in the provided chunk of code.

    To not write lots of untested IO code, please take a look at the apache.commons.io project. Especially at the FileDeleteStrategy class, for file deletion operations.

    Your code might look like that:

    File fin = new File("C:/ABC Statements final/");
    
    for (File file : fin.listFiles()) {
        FileDeleteStrategy.FORCE.delete(file);
    }   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code i have been using....but i need a conditional where it
I have been using the following code to loop through specific classes in my
I have been using echo $.sprintf(%01\$.2f,$numvar); for my USD formatting, but I only copied
I'm doing very frequent searches in arrays of objects and have been using jQuery.inArray().
I've been working on a piece of code recently where performance is very important,
I have been parsing a GraphViz file for a specific identifer using Regex. Here
I have been parsing a GraphViz file for a specific identifer using Regex. Here
I have been using readLines() to scrape information from a website in an R
I'm relatively new to NHibernate, but have been using it for the last few
I have been using IIS express as my web server for awhile now, but

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.