Java Reference
In-Depth Information
}
static
static class
class
DemoService
DemoService
implements
implements
Runnable
{
public
public
void
void
run
() {
try
try
{
Thread
.
sleep
(
1000
);
System
.
out
.
println
(
"Creating file"
);
new
new
File
(
tempDirPath
+
"/MyFileSema.for"
).
createNewFile
();
Thread
.
sleep
(
1000
);
System
.
out
.
println
(
"Stopping WatcherServiceDemo"
);
done
=
true
true
;
Thread
.
sleep
(
1500
);
mainRunner
.
interrupt
();
}
catch
catch
(
Exception e
) {
System
.
out
.
println
(
"Caught UNEXPECTED "
+
e
);
}
}
}
}
Program: Find
The program shown in
Example 11-2
implements a small subset of the Windows
Find Files
dialog or the Unix
find
command. However, it has much of the structure needed to build a
more complete version of either of these. It uses a custom filename filter controlled by the
-n
the reader.
Example 11-2. src/main/java/dir_file/Find.java
/**
* Find - find files by name, size, or other criteria. Non-GUI version.
*/
public
public class
Find
{
/** Main program */
public
class
Find
public static
void
main
(
String
[]
args
) {
Find finder
=
new
static
void
new
Find
();
GetOpt argHandler
=
new
new
GetOpt
(
"n:s:"
);
int
int
c
;
while
while
((
c
=
argHandler
.
getopt
(
args
)) !=
GetOpt
.
DONE
) {
switch
switch
(
c
) {
case
case
'n'
:
finder
.
filter
.
setNameFilter
(
argHandler
.
optarg
());
break
break
;