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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T14:13:21+00:00 2026-06-10T14:13:21+00:00

Why file.mkdir is returning false? Google indicates that there could be several reasons (e.g.

  • 0

Why file.mkdir is returning false?

Google indicates that there could be several reasons (e.g. security, permissions, pathname, etc).

My questions:

  1. How to find the exact reason of returning false?
  2. If security/permissions is a reason, then why is SecurityException not thrown?
  • 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-10T14:13:23+00:00Added an answer on June 10, 2026 at 2:13 pm

    If security/permissions is a reason, then why is SecurityException NOT thrown (which is mentioned in javadoc)?

    A SecurityException is thrown when you don’t have JVM-level permission to do something, not OS-level

    Is there a way to find the exact reason why of returning false?

    No, AFAIK. The only way to know would be to check the permissions on the directory yourself, make sure it doesn’t exist before calling them, check if the parent directory exists, etc.

    However, if you’re using Java 7 or higher, you can use NIO instead to create the directory. Specifically, Files.createDirectory:

    File dir = new File("mydir");
    Files.createDirectory(dir.toPath());
    

    If you want to use NIO entirely without using java.io.File, you can use Paths.get to create a Path instead:

    Path dir = Paths.get("mydir");
    Files.createDirectory(dir);
    

    In both cases, if the directory can’t be created, it will throw an IOException with an exact reason for why the operation failed.

    This is true for most of the methods in Files, and so using it is recommended over using the methods in the File class.

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

Sidebar

Related Questions

I have a Window .bat file with DOS commands that involve REM, MKDIR, ECHO,
While using File.mkdir , and friends I notice that they don't throw exceptions on
How do I find out why java.io.File.mkdir() returns false . I can create the
I have a file like this. rm a.txt mkdir foo cp a.doc docs I
Look at the following code: ECHO A2 MKDIR -v /tmp/My Batch Script File Assignment
Form docs: Comparable c=mock(Comparable.class); when(c.compareTo(anyInt())).thenReturn(-1); I would like: File tempDir=new File(test); Comparable c=mock(Comparable.class); when(c.compareTo(anyInt())).thenReturn(tempDir.mkdir());
Hey everyone, I have written a script that downloads a zip file from a
DOWNLOAD_PATH=sample.ext RATE_LIMIT=300K mkdir ../$DOWNLOAD_PATH BASE_COMMAND=screen wget --continue --directory-prefix=../$DOWNLOAD_PATH --tries=2 --input-file=$DOWNLOAD_PATH $(${BASE_COMMAND} --limit-rate=${RATE_LIMIT}) This does
File mediaDir = new File(media); if (!mediaDir.exists()){ mediaDir.createNewFile(); mediaDir.mkdir(); } File f = new
I currently have the following script: mkdir \\file-srv\Archive\Products\Web\AccountsServices\Account.Toolbar\Nightly\Accounts-4.2-TC-new\%system.build.number% xcopy /I /E /Y %env.working_directory%\Deployment\Account\Release\*.* \\file-srv\Archive\Products\Web\AccountsServices\Account.Toolbar\Nightly\Accounts-4.2-TC-new\%system.build.number%

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.