/Users/lyon/j4p/src/bookExamples/ch14Files/FileExamples.java
|
1 package bookExamples.ch14Files;
2
3 import futils.DirList;
4 import futils.Futil;
5 import futils.WildFilter;
6 import gui.In;
7
8 import java.io.File;
9
10 /**
11 * DocJava, Inc.
12 * http://www.docjava.com
13 * Programmer: dlyon
14 * Date: Oct 18, 2004
15 * Time: 2:44:21 PM
16 */
17 public class FileExamples {
18 public static void main(String[] args) {
19 getSubdirectoryExample();
20 }
21
22 /**
23 * list all the files in a given directory and its subdirectories.
24 */
25 private static void getSubdirectoryExample() {
26 String suffix = In.getString("enter a suffix for a file list");
27 String prefix = In.getString("enter a prefix for a file list");
28 String midfix = In.getString("enter a midfix for a file list");
29 WildFilter fnf = new WildFilter(prefix, midfix, suffix);
30 DirList d = new DirList(fnf);
31 File f[] = d.getFiles();
32 if (f == null || f.length == 0) {
33 In.message("no files found with ");
34 return;
35 }
36 File aFile = (File)
37 In.multiPrompt(f, "select a file", "file selection dialog");
38 In.message("you select:" + aFile);
39
40 }
41
42 private static void getFileExample() {
43 String suffix = In.getString("enter a suffix for a file list");
44 WildFilter fnf = new WildFilter(suffix);
45 File dir = Futil.getReadDirFile("select a directory containing files that end with "
46 + suffix);
47 File f[] = dir.listFiles(fnf);
48 if (f == null || f.length == 0) {
49 In.message("no files found with " + suffix + " suffix.");
50 return;
51 }
52 File aFile = (File)
53 In.multiPrompt(f, "select a file", "file selection dialog");
54 In.message("you select:" + aFile);
55 }
56
57 private static void getDirExample() {
58 In.message("welcome to my file examples!");
59 File f = futils.Futil.getReadDirFile("select a directory");
60 In.message("you selected:" + f.getAbsolutePath());
61 }
62 }
63