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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:54:49+00:00 2026-06-05T18:54:49+00:00

The problem: I need to ensure that a particular directory hierarchy exists in the

  • 0

The problem: I need to ensure that a particular directory hierarchy exists in the file system, and create it if it doesn’t.

I know that there is the method File.mkdirs() however the javadocs for that method indicate that it could fail creating some or all of the directories necessary to complete the path given.

To get around that, I made a method that takes a String representing the path and parses it into the individual parts, storing them into an ArrayList<String>. A second method would then go through and build the directories up, making sure that each directory and sub directory existed.

The problem is, the actual program runs out of memory when trying to loop through and break up the string into its individual parts. I know it’s not the function; it works perfectly on its own in a JUnit test, and the program itself isn’t very memory intensive. At this point, it’s just set directories up and stored them into a “DataBank” class – nothing big, just a class storing a bunch of strings.

I’d like to figure out what’s causing the problem; I can reply with the different classes in effect at the point the code stops.

However, a simpler solution might just be to use File.mkdirs(). What would cause File.mkdirs() to not create directories? Would it just be insufficient permissions?

I’d like to simplify the process if I can, instead of trying to re-invent the wheel. At the same time, though, I know that the program should not be running out of memory – I’m storing Strings and performing file operations, nothing super intensive.

  • 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-05T18:54:50+00:00Added an answer on June 5, 2026 at 6:54 pm

    However, a simpler solution might just be to use File.mkdirs(). What would cause File.mkdirs() to not create directories? Would it just be insufficient permissions?

    File.mkdirs() could fail for any of the reasons that File.mkdir() fails (except for failing due to the parent directory not existing (for obvious reasons)).

    From the Javadoc:

    public boolean mkdirs()

    Creates the directory named by this abstract pathname, including any necessary but nonexistent parent directories. Note that if this operation fails it may have succeeded in creating some of the necessary parent directories

    The bold bit is a clue that mkdirs() is just a shortcut for multiple calls to mkdir().

    Here’s what mkdirs() does – it effectively calls mkdir() up the directory hierarchy:

    public boolean mkdirs() {
        if (exists()) {
            return false;
        }
        if (mkdir()) {
            return true;
        }
        File canonFile = null;
        try {
            canonFile = getCanonicalFile();
        } catch (IOException e) {
            return false;
        }
    
        File parent = canonFile.getParentFile();
        return (parent != null && (parent.mkdirs() || parent.exists()) &&
                canonFile.mkdir());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Problem: I need to write/read objects from a file.This because I need to write/read
My problem : I need to create draggable widgets (here it's a jslider for
My main problem is that I need to enable multiple OS processes to communicate
I have a function that accepts an Enumerable. I need to ensure that the
I need a regular expression for my password format. It must ensure that password
How can I ensure that my custom field's *to_python()* method is only called when
How can I ensure that my custom field's *to_python()* method is only called when
I'm have difficulty with a seeming simple problem. There are various C functions that
I need to change the url of a directory so that: www.example.com/foo/ becomes www.example.com
I'd like to ensure that there's never a line break between a radio button

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.