Page 2 of 3
FilenameFilter is implemented in the class EOLConverter so that only files with the extensions .htm, .html, .java, and .txt are converted. The method accept of this interface is overwritten from lines 09 to 17.main, the method convertDirectory is invoked. The string object (".") represents the current directory (in which you have started the EOLConverter program).accept is the only method that needs to be overwritten if you implement a FilenameFilter. In line 10, the complete path of a directory or file is determined. If the path represents a directory, the value of the
boolean variable in line 11 is true and the method return in line 16 returns true. During the execution of the statements from lines 12 to 15, we check to see whether the file has one of the above extensions.
At this point, you are invited to also accept files with other extensions.list gets the implemented FilenameFilter via the construction of an object of the current class as its argument. The previously discussed method accept is called automatically for you at this point.After that, we examine all list entries to determine whether each is a directory or a file. If the list entry is a directory,
we execute the current block again by recalling the method in line 19, but now with our current entry as the new argument.
This is the most important statement of the program EOLConverter, because now all the files in the child directories are converted. However, this is also a dangerous statement; you may run
into memory problems if you have too many child directories to convert. If the list entry isn't a directory, the method convertFile is invoked to convert the line separator.
The statement in line 23 is set apart with comment tags because we call a method of the class PrintStream on the object out of the class System. To execute this statement, your operating system must have a standard output device. If this is the case, feel free to uncomment
the statement and observe the application doing its job.
The execution flow of the application can be summarized as follows: First, create a list of all directories and all files with the specified extensions. Then, determine for each list entry whether it is a directory or a file. If a list entry is a file, the line separator is converted by shipping its text lines into a temporary file, which is renamed after the conversion process has finished. If a list entry is a directory, you must create a new list for this directory and repeat the process.
java.io.*, see the following section of the Java Tutorial http://java.sun.com/docs/books/tutorial/essential/io/index.html
BufferedReader class at http://java.sun.com/products/jdk/1.2/docs/api/java/io/BufferedReader.html
BufferedWriter class at http://java.sun.com/products/jdk/1.2/docs/api/java/io/BufferedWriter.html