openjdk/jdk · warning · IOException
Cannot create directory
Error message
Cannot create directory
What it means
IOException from ExampleFileSystemView.createNewFolder when File.mkdir() returns false — the OS refused to create the 'New folder' directory. mkdir fails without throwing, so the demo converts the boolean into an IOException, losing the OS error detail.
Source
Thrown at src/demo/share/jfc/FileChooserDemo/ExampleFileSystemView.java:67
* You can provide a superclass of the FileSystemView class with your own functionality.
*
* @author Pavel Porvatov
*/
public class ExampleFileSystemView extends FileSystemView {
/**
* Creates a new folder with the default name "New folder". This method is invoked
* when the user presses the "New folder" button.
*/
public File createNewFolder(File containingDir) throws IOException {
File result = new File(containingDir, "New folder");
if (result.exists()) {
throw new IOException("Directory 'New folder' exists");
}
if (!result.mkdir()) {
throw new IOException("Cannot create directory");
}
return result;
}
/**
* Returns a list which appears in a drop-down list of the FileChooser component.
* In this implementation only the home directory is returned.
*/
@Override
public File[] getRoots() {
return new File[] { getHomeDirectory() };
}
/**
* Returns a string that represents a directory or a file in the FileChooser component.
* A string with all upper case letters is returned for a directory.
* A string with all lower case letters is returned for a file.View on GitHub (pinned to 88dfb74bbe)
Solutions
- Choose a writable parent directory before creating a folder.
- Check containingDir.isDirectory() && containingDir.canWrite() beforehand.
- In adapted code, use java.nio.Files.createDirectory which reports the real errno.
Example fix
// before
if (!result.mkdir()) throw new IOException("Cannot create directory");
// after: real error surfaced
try {
Files.createDirectory(result.toPath());
} catch (IOException e) {
throw new IOException("Cannot create " + result + ": " + e.getMessage(), e);
} Defensive patterns
Strategy: validation
Validate before calling
// verify the parent is a writable directory before mkdir
if (containingDir == null || !containingDir.isDirectory() || !containingDir.canWrite())
throw new IOException("cannot create folder in " + containingDir); Try / catch
try {
Files.createDirectory(result.toPath());
} catch (FileAlreadyExistsException e) {
// pick another name
} catch (AccessDeniedException e) {
// tell the user the directory is read-only
} catch (IOException e) {
// surface the real errno-based message
} Prevention
- Prefer java.nio.file.Files.createDirectory over File.mkdir — it reports the actual cause.
- Check canWrite()/isDirectory() on the parent before offering the 'New folder' action in the UI.
When it happens
Trigger: containingDir is read-only, does not exist, is a file, or the filesystem denies mkdir (permissions, immutable attribute, sandbox).
Common situations: User browsing into a read-only mount or system directory in the demo; disk full; macOS/Windows protected directories; applications reusing the demo view against restricted filesystems.
Related errors
- Directory 'New folder' exists
- ERROR: drawBytes cannot handle characters beyond 0x00FF. Sel
- ERROR: Cannot fit text with the current font size. Resize th
- ERROR: Cannot print with the current font size. Use smaller
- error writing property file
AI-assisted analysis of openjdk/jdk@88dfb74bbe (2026-08-14).
Data as JSON: /api/errors/0215b43947f40d18.
Report an issue: GitHub.