Chapter 4: Creating a File Search Application


The New Input/Output (NIO) API supports the java.nio, java.nio.channels, and java.util.regex packages for buffer management, character conversion, and regular expression matching. The java.nio and java.nio.channels packages contain the File, FileChannel, and CharBuffer classes to read and buffer the contents of a file. The java.util.regex package provides the Pattern and Matcher classes to match regular expressions.

This chapter explains how to develop a File Search application, which uses the above-mentioned NIO packages to search for specific files.

Architecture of the File Search Application

The File Search application enables an end user to search for files that are available at a specific location and contain a specific text pattern. The application also searches for all the instances of the specified text pattern in the files and displays the start position of the pattern to end users.

The File Search application uses the following files:

  • Search.java : Creates a user interface that helps an end user specify the criteria to search for specific files and view the retrieved result

  • FileList.java : Searches for files that are available at the specified location and contain the specified text pattern

  • Help.java : Creates a window that lists the steps to use the File Search application

Figure 4-1 shows the architecture of the File Search application:

click to expand: this figure shows the various files used in the file search application and the sequence in which they are used.
Figure 4-1: Architecture of the File Search Application

In the File Search application, the Search.java file calls the FileList.java file to search for files that are present at the specified location and contain the specified text pattern. The FileList.java file searches for these files and passes the search results to the Search.java file. The Search.java file then displays these results to the end user in a tabular format. Before starting the file search process, if an end user opts to view the application help file, the Search.java file calls the Help.java file to display the steps to use the File Search application.




Java InstantCode. Developing Applications Using Java NIO
Java InstantCode. Developing Applications Using Java NIO
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 55

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net