Fix java.nio.file.AccessDeniedException in Kafka on Windows
Codemia Knowledge Hub ·
On Windows, Kafka throws java.nio.file.AccessDeniedException when its process cannot access or modify a file or directory: usually because the account running Kafka lacks permissions on the log directory, or because another process has the file locked. Fix the permissions, find what holds the lock, and check the directory paths in your configuration.
Where the exception comes from
The exception is thrown by Java's NIO file package, which Kafka uses for file operations. It indicates a permission problem at the operating system level.
It typically appears in three situations:
- Log directory access: Kafka stores commit logs in log directories. If the account running Kafka lacks read/write permission, it cannot use them.
- Temp directory use: Kafka and the Java runtime may use temporary directories for operations like log compaction, and access problems there also cause the exception.
- Locked files: on Windows, other processes can lock files even when permissions are correct. Antivirus programs and files left open in other programs are common culprits.
How to fix it
- Check and fix folder permissions:
- Right-click the folder (for example the Kafka log directory) and select Properties.
- On the Security tab, check that the user running Kafka has Full control or at least Modify.
- If not, click Edit to change the permissions.
- Run Kafka as administrator:
- Right-click the Kafka start script and choose "Run as administrator."
- Running software as administrator carries security risks.
- Find processes locking the files:
- Use a tool like Process Explorer to identify and stop processes that lock Kafka's files.
- Make sure no unnecessary software is accessing Kafka's directories.
- Check Kafka and ZooKeeper configuration:
- Confirm that Kafka's
server.propertiesand ZooKeeper'szoo.cfgpoint to the right directories with the right permissions.
Reading the Kafka logs
Kafka's logs, often in the ./logs/ directory, show what operation was attempted and what was denied. An entry might look like:
Preventing it from coming back
- Recheck permissions after updates or configuration changes.
- Periodically check for permission issues and lock conflicts.
- Run Kafka under a dedicated user account with only the permissions it needs.
| Issue Component | Problem Description | Solution/Action |
| Permission | Insufficient file/directory permissions | Adjust permissions, run Kafka as administrator |
| Locked Files | Files locked by other Windows processes | Use Process Explorer to unlock files |
| Configuration | Incorrect paths or settings in configuration | Verify server.properties and zoo.cfg files |
Related reading
- Getting Multiple messages on spark-submit seeking to EARLIEST and Resetting offset for partition topic-partition
- Getting number of messages in a RabbitMQ queue
- Getting PreconditionFailed - inequivalent arg 'x-max-priority' for queue error when trying to set up priority queues with Celery+RabbitMQ
- Golang - RabbitMq channel/connection is not open
- Getting NoSuchMethodError javax.servlet.ServletContext.addServlet in Spring Boot while running a Spring MVC application
- Getting NullPointerException while connecting with ignite server node
- Golang TLS with Kafka-Go and Certificates. No Connection
- Good practice when using kafka with jpa
System design interview problems on this topic
- Design a Distributed Messaging System: solution and walkthrough
- Design a Log Collection and Analysis System: solution and walkthrough
- Design an Ad Click Aggregation System: solution and walkthrough
- Design a Webhook Notification Service: solution and walkthrough

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseSystem Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.