Java NIO also known as new input output library as is a set of classes defined under package java.nio.* to access files, file attributes and file systems.
The main classes from this package are:
- Path - to manage file location and directory hierarchy
- Files - to manage file operations
- Walking the file tree
- Watchers - monitoring the creation/modification/deletion of files
- Copy/Create/Delete files from a directory(atomic operations with synchronization)
- Find files using matcher expressions
In the following example we are going to see how to implement a watcher. This is useful when we need a process to monitor when a file is created/modified or deleted in a directory.
Steps in this example:
1- watch for new files in a directory
2- evaluate the mime type of the file
3- if it is a text file it will be copied to other directory.
No comments:
Post a Comment