Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
507 views
in Technique[技术] by (71.8m points)

java - File.mkdir or mkdirs return false - Reason?

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?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

mkdir and mkdirs return false if the directory already exists, so that might be one reason for the failure.

If you are using Java 7, you can use the Files class. It throws an IOException on error with pretty good descriptions.

Files.createDirectory(file.toPath());

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...