Many times you'll want some control over the FileDialog
. You may want to specify that it should start
looking in a particular directory, or that only text files should
be shown. Java lets you do this. To start the FileDialog
off in a particular directory call the FileDialog
's setDirectory(String dir)
method
where dir
is the path to the directory. That is
fd.setDirectory("/usr/tmp");
You can even set the FileDialog
to point at a
particular file using setFile(String filename)
.
However if you already know the file name why do you need to bring
up a FileDialog
? More likely is that you'll want to
look for a particular type of file, for instance text files. To
make this happen you need to use a FilenameFilter
to
specify which files you'll accept. The key method is
setFilenameFilter(FilenameFilter fnf).