|
javax.naming.spi.DirectoryManager search codefetch This class contains methods for supporting DirContext implementations.
javax.swing.filechooser.FileSystemView search codefetch FileSystemView is JFileChooser's gateway to the file system.
javax.swing.plaf.basic.BasicDirectoryModel search codefetch Basic implementation of a file list.
javax.naming.directory.BasicAttribute search codefetch This class provides a basic implementation of the Attribute interface.
javax.naming.directory.BasicAttributes search codefetch This class provides a basic implementation of the Attributes interface.
|
|
javax.swing.filechooser.FileSystemView.createFileSystemRoot search codefetch
Creates a new File object for f with correct behavior for a file system root directory.
java.lang.ProcessBuilder.directory search codefetch
Sets this process builder's working directory.
javax.swing.filechooser.FileSystemView.isFileSystem search codefetch
Checks if f represents a real directory or file as opposed to a special folder such as "Desktop".
java.io.File.listFiles search codefetch
Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname ...
javax.imageio.ImageIO.setCacheDirectory search codefetch
Sets the directory where cache files are to be created.
|
| Most relevant API matches shown. View All. |
![]() |
|
|
ch03-Servlets/src/java/com/oreilly/jent/servlets/FileServlet.java (73 lines)
38 import javax.servlet.http.HttpServletResponse;
39
40 public class FileServlet extends HttpServlet {
41
42 public void doGet(HttpServletRequest req, HttpServletResponse resp)
43 throws ServletException, IOException {
44
45 File r;
46 FileReader fr;
47 BufferedReader br;
48 try {
49 r = new File(req.getParameter("filename"));
50 fr = new FileReader(r);
51 br = new BufferedReader(fr);
52 if(!r.isFile( )) { // Must be a directory or something else
53 resp.sendError(HttpServletResponse.SC_NOT_FOUND);
54 return;
|
![]() |
|
|
Beginning Algorithms/Beginning Algorithms/main/com/wrox/algorithms/iteration/RecursiveDirectoryTreePrinter.java (67 lines)
5 /**
6 * Simple class to print out the contents of a directory tree.
7 *
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30 }
31
32 System.out.println("Recursively printing directory tree for: " + args[0]);
33 print(new File(args[0]), "");
34 }
35
36 /**
37 * Prints a list of files/directories with the given indentation.
38 *
39 * @param files The files/directories to print.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 44
45 for (files.first(); !files.isDone(); files.next()) {
46 print((File) files.current(), indent);
47 }
48 }
49
50 /**
51 * Prints a file or directory with the given indentation.
52 *
53 * @param file The file or directory to print.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 61 System.out.println(file.getName());
62
63 if (file.isDirectory()) {
64 print(new ArrayIterator(file.listFiles()), indent + SPACES);
65 }
66 }
Additional matches viewable in cache of Beginning Algorithms/Beginning Algorithms/main/com/wrox/algorithms/iteration/RecursiveDirectoryTreePrinter.java. |
![]() |
|
|
Chapter08/DisplayMySqlClobAsURLServlet.java (131 lines)
17 public class DisplayMySqlClobAsURLServlet extends HttpServlet {
18
19 // directory where clob data will be placed as files.
20 private static final String CLOB_DIRECTORY =
21 "c:/tomcat/webapps/octopus/clobDir";
Additional matches viewable in cache of Chapter08/DisplayMySqlClobAsURLServlet.java. Chapter08/DisplayOracleClobAsURLServlet.java (133 lines)
17 public class DisplayOracleClobAsURLServlet extends HttpServlet {
18
19 // directory where clob data will be placed as files.
20 private static final String CLOB_DIRECTORY =
21 "c:/tomcat/webapps/octopus/clobDir";
Additional matches viewable in cache of Chapter08/DisplayOracleClobAsURLServlet.java. |
![]() |
|
|
beg-crypto-examples/src/chapter8/KeyStoreFileUtility.java (27 lines)
5
6 /**
7 * Create some keystore files in the current directory.
8 */
9 public class KeyStoreFileUtility
|
![]() |
|
|
Ch02-ListsAndCombos/16/PolymorphicJList.java (330 lines)
17
18 ImageIcon fileIcon, textFileIcon, directoryIcon,
19 imageFileIcon, pngFileIcon, gifFileIcon,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 22 imageCellPrototype, directoryCellPrototype;
23 JLabel fileNameLabel, textNameLabel,
24 directoryNameLabel, imageNameLabel,
25 fileSizeLabel,
26 textSizeLabel, textWordCountLabel,
27 directoryCountLabel,
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 61 else if (isImageFile (files [i]))
62 mod.addElement (new ImageFileItem (files[i]));
63 else if (files[i].isDirectory())
64 mod.addElement (new DirectoryItem (files[i]));
65 else
66 mod.addElement (new FileItem (files[i]));
67 }
68 }
69
70 protected boolean isImageFile(File f) {
71 if (f.isDirectory())
72 return false;
73 String name = f.getName();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 245 public int getChildCount() { return childCount; }
246 void initChildCount () {
247 if (! file.isDirectory())
248 childCount = -1;
249 else
250 childCount = file.listFiles().length;
251 System.out.println (file.getPath() + ": " + childCount + " items");
252 }
Additional matches viewable in cache of Ch02-ListsAndCombos/16/PolymorphicJList.java. Ch04-FileChoosers/32/DebugFile.java (222 lines)
109
110 public boolean isDirectory() {
111 p("is directory");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 200 */
201 /*
202 Returns an array of abstract pathnames denoting the files in the directory denoted by this abstract pathname.
203 File[] listFiles(FileFilter filter)
204 Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
205 File[] listFiles(FilenameFilter filter)
206 Returns an array of abstract pathnames denoting the files and directories in the directory denoted by this abstract pathname that satisfy the specified filter.
207 static File[] listRoots()
208 List the available filesystem roots.
Additional matches viewable in cache of Ch04-FileChoosers/32/DebugFile.java. Ch04-FileChoosers/32/ZipFileSystemView.java (83 lines)
6
7 public class ZipFileSystemView extends FileSystemView {
8
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 38 return dir.getParentFile();
39 }
40 return super.getParentDirectory(dir);
41 }
42
43 public File[] getFiles(File dir, boolean useFileHiding) {
44 if(dir.getName().endsWith(".zip")) {
45 ZipFileProxy proxy = new ZipFileProxy(dir);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52 }
53
54 return super.getFiles(dir,useFileHiding);
55 }
56
57 public Boolean isTraversable(File f) {
58 if(f.getName().endsWith(".zip")) {
59 return new Boolean(true);
60 }
61 if(f instanceof ZipEntryFileProxy) {
62 boolean b = ((ZipEntryFileProxy)f).isDirectory();
63 return new Boolean(b);
64 }
Additional matches viewable in cache of Ch04-FileChoosers/32/ZipFileSystemView.java. Ch04-FileChoosers/30/ShortcutFileSystemView.java (61 lines)
2 import javax.swing.Icon;
3 import javax.swing.filechooser.FileSystemView;
4
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 23
24
25 /* =================== FileSystemView implementation ===================== */
26 private boolean isDirLink(File f) {
27 try {
28 if(f.getName().toLowerCase().endsWith(".lnk")) {
29 if(new LnkParser(f).isDirectory()) {
30 return true;
31 }
Additional matches viewable in cache of Ch04-FileChoosers/30/ShortcutFileSystemView.java. Ch04-FileChoosers/32/ZipFileProxy.java (75 lines)
36 String name = full_name;
37 if(ze.isDirectory()) {
38 name = full_name.substring(0,full_name.length()-1);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 51 }
52
53 if(ze.isDirectory()) {
54 HashMap children = new HashMap();
55 hash.put(full_name,children);
56 }
57 Map parent_children = (Map)hash.get(parent);
58 parent_children.put(full_name,"");
59 }
60 }
61
62 public File[] getFiles(String dir) {
63 Map children = (Map)hash.get(dir);
64 File[] files = new File[children.size()];
Additional matches viewable in cache of Ch04-FileChoosers/32/ZipFileProxy.java. |
![]() |
|
|
Ch09/FileSample.java (49 lines)
5 import javax.swing.filechooser.*;
6
7 public class FileSample {
8
9 public static void main(String args[]) {
10 Runnable runner = new Runnable() {
11 public void run() {
12 JFrame frame = new JFrame("JFileChooser Popup");
13 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
14
15 final JLabel directoryLabel = new JLabel();
16 frame.add(directoryLabel, BorderLayout.NORTH);
17
Additional matches viewable in cache of Ch09/FileSample.java. Ch09/FileSamplePanel.java (49 lines)
4 import javax.swing.*;
5
6 public class FileSamplePanel {
7
8 public static void main(String args[]) {
9 Runnable runner = new Runnable() {
10 public void run() {
11 JFrame frame = new JFrame("JFileChooser Popup");
12 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
13
14 final JLabel directoryLabel = new JLabel(" ");
15 directoryLabel.setFont(new Font("Serif", Font.BOLD | Font.ITALIC, 36));
16 frame.add(directoryLabel, BorderLayout.NORTH);
Additional matches viewable in cache of Ch09/FileSamplePanel.java. |
![]() |
|
|
KGPJ Code/.BAH7503/Installlation Tests/Uninstall Code/DLLUninstallAction.java (83 lines)
5 /* Based on install4j's HelloUninstallAction example.
6
7 Uninstall all the DLL files prior to install4j's general
8 uninstallation process.
9
10 This class is executed in the <PROG_DIR>/.install4j directory,
11 but must delete DLLs in <PROG_DIR>/Executables, which is the
12 reason for the PATH extension.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52 msg = new String("" + (i+1) + "/" + numFiles + ": " + fNms[i] + "... ");
53 deleteFile(fNms[i], progReport, msg);
54 progReport.setPercentCompleted( ((i+1)*100)/numFiles );
55 try {
56 Thread.sleep(500); // 0.5 sec to see something
57 }
58 catch (InterruptedException e) {}
59 }
60 } // end of deleteDLLs()
61
62
63 private static void deleteFile(String dllFnm, ProgressInterface progReport, String msg)
64 // delete the named file from the Executables/ directory
65 {
66 File f = new File(PATH + "/" + dllFnm);
Additional matches viewable in cache of KGPJ Code/.BAH7503/Installlation Tests/Uninstall Code/DLLUninstallAction.java. KGPJ Code/.BAH7576/Installlation Tests/Uninstall Code/DLLUninstallAction.java (83 lines)
5 /* Based on install4j's HelloUninstallAction example.
6
7 Uninstall all the DLL files prior to install4j's general
8 uninstallation process.
9
10 This class is executed in the <PROG_DIR>/.install4j directory,
11 but must delete DLLs in <PROG_DIR>/Executables, which is the
12 reason for the PATH extension.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52 msg = new String("" + (i+1) + "/" + numFiles + ": " + fNms[i] + "... ");
53 deleteFile(fNms[i], progReport, msg);
54 progReport.setPercentCompleted( ((i+1)*100)/numFiles );
55 try {
56 Thread.sleep(500); // 0.5 sec to see something
57 }
58 catch (InterruptedException e) {}
59 }
60 } // end of deleteDLLs()
61
62
63 private static void deleteFile(String dllFnm, ProgressInterface progReport, String msg)
64 // delete the named file from the Executables/ directory
65 {
66 File f = new File(PATH + "/" + dllFnm);
Additional matches viewable in cache of KGPJ Code/.BAH7576/Installlation Tests/Uninstall Code/DLLUninstallAction.java. KGPJ Code/Installlation Tests/Uninstall Code/DLLUninstallAction.java (83 lines)
5 /* Based on install4j's HelloUninstallAction example.
6
7 Uninstall all the DLL files prior to install4j's general
8 uninstallation process.
9
10 This class is executed in the <PROG_DIR>/.install4j directory,
11 but must delete DLLs in <PROG_DIR>/Executables, which is the
12 reason for the PATH extension.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52 msg = new String("" + (i+1) + "/" + numFiles + ": " + fNms[i] + "... ");
53 deleteFile(fNms[i], progReport, msg);
54 progReport.setPercentCompleted( ((i+1)*100)/numFiles );
55 try {
56 Thread.sleep(500); // 0.5 sec to see something
57 }
58 catch (InterruptedException e) {}
59 }
60 } // end of deleteDLLs()
61
62
63 private static void deleteFile(String dllFnm, ProgressInterface progReport, String msg)
64 // delete the named file from the Executables/ directory
65 {
66 File f = new File(PATH + "/" + dllFnm);
Additional matches viewable in cache of KGPJ Code/Installlation Tests/Uninstall Code/DLLUninstallAction.java. |
![]() |
|
|
examples/ch12/ListIt.java (30 lines)
11 }
12
13 if ( file.isDirectory( ) ) {
14 String [] files = file.list( );
15 for (int i=0; i< files.length; i++)
16 System.out.println( files[i] );
|
![]() |
|
|
code/src/com/oreilly/qtjnotebook/ch03/AddAudioTrackQTEditor.java (453 lines)
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 210 fd.setVisible(true); // blocks
211 if ((fd.getDirectory() == null) ||
212 (fd.getFile() == null))
213 return;
214 file = new QTFile (new File (fd.getDirectory(),
215 fd.getFile()));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 234 fd.setVisible(true); // blocks
235 if ((fd.getDirectory() == null) ||
236 (fd.getFile() == null))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 238 QTFile flatFile =
239 new QTFile (new File (fd.getDirectory(),
240 fd.getFile()));
code/src/com/oreilly/qtjnotebook/ch03/FlattenableQTEditor.java (403 lines)
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 201 fd.setVisible(true); // blocks
202 if ((fd.getDirectory() == null) ||
203 (fd.getFile() == null))
204 return;
205 file = new QTFile (new File (fd.getDirectory(),
206 fd.getFile()));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 225 fd.setVisible(true); // blocks
226 if ((fd.getDirectory() == null) ||
227 (fd.getFile() == null))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 229 QTFile flatFile =
230 new QTFile (new File (fd.getDirectory(),
231 fd.getFile()));
code/src/com/oreilly/qtjnotebook/ch03/RefSaveableQTEditor.java (429 lines)
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 205 fd.setVisible(true); // blocks
206 if ((fd.getDirectory() == null) ||
207 (fd.getFile() == null))
208 return;
209 file = new QTFile (new File (fd.getDirectory(),
210 fd.getFile()));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 229 fd.setVisible(true); // blocks
230 if ((fd.getDirectory() == null) ||
231 (fd.getFile() == null))
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 233 QTFile flatFile =
234 new QTFile (new File (fd.getDirectory(),
235 fd.getFile()));
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 267 fd.setVisible(true); // blocks
268 if ((fd.getDirectory() == null) ||
269 (fd.getFile() == null))
270 return;
271 file = new QTFile (new File (fd.getDirectory(),
272 fd.getFile()));
code/src/com/oreilly/qtjnotebook/ch04/GraphicImportExport.java (152 lines)
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 128 exporter.getDefaultFileNameExtension();
129 File file = new File (fd.getDirectory(), filename);
130 exporter.setOutputFile (new QTFile(file));
code/src/com/oreilly/qtjnotebook/ch08/VideoSampleBuilder.java (326 lines)
5 Permission is hereby granted, free of charge, to any person obtaining a
6 copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 56 /* try to load "videoSampleBuilder.properties" from
57 current directory. this contains file.location and
58 start.x/y/width/height and end.x/y/width/height params
|
![]() |
|
|
LuceneInAction/src/lia/handlingtypes/framework/FileIndexer.java (95 lines)
5 import org.apache.lucene.index.IndexReader;
6 import org.apache.lucene.store.Directory;
7 import org.apache.lucene.store.FSDirectory;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30
31 if (file.canRead()) {
32 if (file.isDirectory()) {
33 String[] files = file.list();
34 if (files != null) {
35 for (int i = 0; i < files.length; i++) {
Additional matches viewable in cache of LuceneInAction/src/lia/handlingtypes/framework/FileIndexer.java. LuceneInAction/src/lia/meetlucene/Indexer.java (84 lines)
29 long end = new Date().getTime();
30
31 System.out.println("Indexing " + numIndexed + " files took "
32 + (end - start) + " milliseconds");
33 }
34
35 public static int index(File indexDir, File dataDir)
36 throws IOException {
37
38 if (!dataDir.exists() || !dataDir.isDirectory()) {
39 throw new IOException(dataDir
40 + " does not exist or is not a directory");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 53 }
54
55 private static void indexDirectory(IndexWriter writer, File dir)
56 throws IOException {
57
58 File[] files = dir.listFiles();
59
60 for (int i = 0; i < files.length; i++) {
61 File f = files[i];
62 if (f.isDirectory()) {
63 indexDirectory(writer, f); // recurse
64 } else if (f.getName().endsWith(".txt")) {
Additional matches viewable in cache of LuceneInAction/src/lia/meetlucene/Indexer.java. LuceneInAction/src/lia/tools/BerkeleyDbIndexer.java (63 lines)
9
10 import org.apache.lucene.store.db.DbDirectory;
11 import org.apache.lucene.index.IndexWriter;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 33 for (int i = 0; i < files.length; i++)
34 if (files[i].getName().startsWith("__"))
35 files[i].delete();
36 dbHome.delete();
37 }
38
39 dbHome.mkdir();
40
41 env.open(indexDir, Db.DB_INIT_MPOOL | flags, 0);
42 index.open(null, "__index__", null, Db.DB_BTREE, flags, 0);
43 blocks.open(null, "__blocks__", null, Db.DB_BTREE, flags, 0);
44
45 DbDirectory directory = new DbDirectory(null, index, blocks, 0);
46 IndexWriter writer = new IndexWriter(directory,
47 new StandardAnalyzer(),
Additional matches viewable in cache of LuceneInAction/src/lia/tools/BerkeleyDbIndexer.java. |
![]() |
|
|
Code/Ch21/Sketcher10/SketchFrame.java (553 lines)
61
62 if(!DEFAULT_DIRECTORY.exists()) {
63 if(!DEFAULT_DIRECTORY.mkdirs()) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 68 }
69 }
70 files = new JFileChooser(DEFAULT_DIRECTORY);
71 this.theApp = theApp; // Save application object reference
72 setJMenuBar(menuBar); // Add the menu bar to the window
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 203 files.addChoosableFileFilter(sketchFilter); // Add the filter
204 files.setFileFilter(sketchFilter); // and select it
205 files.rescanCurrentDirectory();
206 files.setSelectedFile(file);
207 files.rescanCurrentDirectory();
208 files.setSelectedFile(file);
209 int result = files.showDialog(SketchFrame.this, null); // Show the dialog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 222 "Save",
223 "Save the sketch",
224 new File(files.getCurrentDirectory(), filename));
225 if(file == null || (file.exists() && // Check for existence
226 JOptionPane.NO_OPTION == // Overwrite warning
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 389 "Save the sketch",
390 modelFile == null ? new File(
391 files.getCurrentDirectory(),
392 filename):modelFile);
393 if(file != null) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 420 modelFile = null; // No file for it
421 filename = DEFAULT_FILENAME; // Default name
422 setTitle(frameTitle + files.getCurrentDirectory() + "\\" + filename);
423 sketchChanged = false; // Not changed yet
424 } if(name.equals(printAction.getValue(NAME))) {
Additional matches viewable in cache of Code/Ch21/Sketcher10/SketchFrame.java. Code/Ch21/Sketcher11/SketchFrame.java (562 lines)
61
62 if(!DEFAULT_DIRECTORY.exists()) {
63 if(!DEFAULT_DIRECTORY.mkdirs()) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 68 }
69 }
70 files = new JFileChooser(DEFAULT_DIRECTORY);
71 this.theApp = theApp; // Save application object reference
72 setJMenuBar(menuBar); // Add the menu bar to the window
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 212 files.addChoosableFileFilter(sketchFilter); // Add the filter
213 files.setFileFilter(sketchFilter); // and select it
214 files.rescanCurrentDirectory();
215 files.setSelectedFile(file);
216 files.rescanCurrentDirectory();
217 files.setSelectedFile(file);
218 int result = files.showDialog(SketchFrame.this, null); // Show the dialog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 231 "Save",
232 "Save the sketch",
233 new File(files.getCurrentDirectory(), filename));
234 if(file == null || (file.exists() && // Check for existence
235 JOptionPane.NO_OPTION == // Overwrite warning
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 401 "Save the sketch",
402 modelFile == null ? new File(
403 files.getCurrentDirectory(),
404 filename):modelFile);
405 if(file != null) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 432 modelFile = null; // No file for it
433 filename = DEFAULT_FILENAME; // Default name
434 setTitle(frameTitle + files.getCurrentDirectory() + "\\" + filename);
435 sketchChanged = false; // Not changed yet
436 } if(name.equals(printAction.getValue(NAME))) {
Additional matches viewable in cache of Code/Ch21/Sketcher11/SketchFrame.java. Code/Ch21/Sketcher12/SketchFrame.java (567 lines)
62
63 if(!DEFAULT_DIRECTORY.exists()) {
64 if(!DEFAULT_DIRECTORY.mkdirs()) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 69 }
70 }
71 files = new JFileChooser(DEFAULT_DIRECTORY);
72 this.theApp = theApp; // Save application object reference
73 setJMenuBar(menuBar); // Add the menu bar to the window
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 213 files.addChoosableFileFilter(sketchFilter); // Add the filter
214 files.setFileFilter(sketchFilter); // and select it
215 files.rescanCurrentDirectory();
216 files.setSelectedFile(file);
217 files.rescanCurrentDirectory();
218 files.setSelectedFile(file);
219 int result = files.showDialog(SketchFrame.this, null); // Show the dialog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 232 "Save",
233 "Save the sketch",
234 new File(files.getCurrentDirectory(), filename));
235 if(file == null || (file.exists() && // Check for existence
236 JOptionPane.NO_OPTION == // Overwrite warning
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 405 "Save the sketch",
406 modelFile == null ? new File(
407 files.getCurrentDirectory(),
408 filename):modelFile);
409 if(file != null) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 436 modelFile = null; // No file for it
437 filename = DEFAULT_FILENAME; // Default name
438 setTitle(frameTitle + files.getCurrentDirectory() + "\\" + filename);
439 sketchChanged = false; // Not changed yet
440 } if(name.equals(printAction.getValue(NAME))) {
Additional matches viewable in cache of Code/Ch21/Sketcher12/SketchFrame.java. Code/Ch21/Sketcher13/SketchFrame.java (572 lines)
63
64 if(!DEFAULT_DIRECTORY.exists()) {
65 if(!DEFAULT_DIRECTORY.mkdirs()) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 70 }
71 }
72 files = new JFileChooser(DEFAULT_DIRECTORY);
73 this.theApp = theApp; // Save application object reference
74 setJMenuBar(menuBar); // Add the menu bar to the window
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 218 files.addChoosableFileFilter(sketchFilter); // Add the filter
219 files.setFileFilter(sketchFilter); // and select it
220 files.rescanCurrentDirectory();
221 files.setSelectedFile(file);
222 files.rescanCurrentDirectory();
223 files.setSelectedFile(file);
224 int result = files.showDialog(SketchFrame.this, null); // Show the dialog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 237 "Save",
238 "Save the sketch",
239 new File(files.getCurrentDirectory(), filename));
240 if(file == null || (file.exists() && // Check for existence
241 JOptionPane.NO_OPTION == // Overwrite warning
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 410 "Save the sketch",
411 modelFile == null ? new File(
412 files.getCurrentDirectory(),
413 filename):modelFile);
414 if(file != null) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 441 modelFile = null; // No file for it
442 filename = DEFAULT_FILENAME; // Default name
443 setTitle(frameTitle + files.getCurrentDirectory() + "\\" + filename);
444 sketchChanged = false; // Not changed yet
445 } if(name.equals(printAction.getValue(NAME))) {
Additional matches viewable in cache of Code/Ch21/Sketcher13/SketchFrame.java. Code/Ch21/Sketcher14/SketchFrame.java (579 lines)
62
63 if(!DEFAULT_DIRECTORY.exists()) {
64 if(!DEFAULT_DIRECTORY.mkdirs()) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 69 }
70 }
71 files = new JFileChooser(DEFAULT_DIRECTORY);
72 this.theApp = theApp; // Save application object reference
73 setJMenuBar(menuBar); // Add the menu bar to the window
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 213 files.addChoosableFileFilter(sketchFilter); // Add the filter
214 files.setFileFilter(sketchFilter); // and select it
215 files.rescanCurrentDirectory();
216 files.setSelectedFile(file);
217 files.rescanCurrentDirectory();
218 files.setSelectedFile(file);
219 int result = files.showDialog(SketchFrame.this, null); // Show the dialog
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 232 "Save",
233 "Save the sketch",
234 new File(files.getCurrentDirectory(), filename));
235 if(file == null || (file.exists() && // Check for existence
236 JOptionPane.NO_OPTION == // Overwrite warning
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 415 "Save the sketch",
416 modelFile == null ? new File(
417 files.getCurrentDirectory(),
418 filename):modelFile);
419 if(file != null) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 446 modelFile = null; // No file for it
447 filename = DEFAULT_FILENAME; // Default name
448 setTitle(frameTitle + files.getCurrentDirectory() + "\\" + filename);
449 sketchChanged = false; // Not changed yet
450 } if(name.equals(printAction.getValue(NAME))) {
Additional matches viewable in cache of Code/Ch21/Sketcher14/SketchFrame.java. |
![]() |
|
|
v1/v1ch12/FindDirectories/FindDirectories.java (40 lines)
11 {
12 // if no arguments provided, start at the parent directory
13 if (args.length == 0) args = new String[] { ".." };
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 18 String[] fileNames = pathName.list();
19
20 // enumerate all files in the directory
21 for (int i = 0; i < fileNames.length; i++)
22 {
Additional matches viewable in cache of v1/v1ch12/FindDirectories/FindDirectories.java. v2/v2ch1/BlockingQueueTest/BlockingQueueTest.java (124 lines)
9 Scanner in = new Scanner(System.in);
10 System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): ");
11 String directory = in.nextLine();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 26
27 /**
28 This task enumerates all files in a directory and its subdirectories.
29 */
30 class FileEnumerationTask implements Runnable
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 32 /**
33 Constructs a FileEnumerationTask.
34 @param queue the blocking queue to which the enumerated files are added
35 @param startingDirectory the directory in which to start the enumeration
36 */
37 public FileEnumerationTask(BlockingQueue<File> queue, File startingDirectory)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 52
53 /**
54 Recursively enumerates all files in a given directory and its subdirectories
55 @param directory the directory in which to start
56 */
57 public void enumerate(File directory) throws InterruptedException
58 {
59 File[] files = directory.listFiles();
60 for (File file : files) {
61 if (file.isDirectory()) enumerate(file);
62 else queue.put(file);
63 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 67
68 private BlockingQueue<File> queue;
69 private File startingDirectory;
70 }
71
72 /**
73 This task searches files for a given keyword.
74 */
75 class SearchTask implements Runnable
Additional matches viewable in cache of v2/v2ch1/BlockingQueueTest/BlockingQueueTest.java. v2/v2ch1/FutureTest/FutureTest.java (112 lines)
9 Scanner in = new Scanner(System.in);
10 System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): ");
11 String directory = in.nextLine();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 13 String keyword = in.nextLine();
14
15 MatchCounter counter = new MatchCounter(new File(directory), keyword);
16 FutureTask<Integer> task = new FutureTask<Integer>(counter);
17 Thread t = new Thread(task);
18 t.start();
19 try
20 {
21 System.out.println(task.get() + " matching files.");
22 }
23 catch (ExecutionException e)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30
31 /**
32 This task counts the files in a directory and its subdirectories that contain a given keyword.
33 */
34 class MatchCounter implements Callable<Integer>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 50 try
51 {
52 File[] files = directory.listFiles();
53 ArrayList<Future<Integer>> results = new ArrayList<Future<Integer>>();
54
55 for (File file : files)
56 if (file.isDirectory())
57 {
58 MatchCounter counter = new MatchCounter(file, keyword);
Additional matches viewable in cache of v2/v2ch1/FutureTest/FutureTest.java. v2/v2ch1/ThreadPoolTest/ThreadPoolTest.java (118 lines)
9 Scanner in = new Scanner(System.in);
10 System.out.print("Enter base directory (e.g. /usr/local/jdk5.0/src): ");
11 String directory = in.nextLine();
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 15 ExecutorService pool = Executors.newCachedThreadPool();
16
17 MatchCounter counter = new MatchCounter(new File(directory), keyword, pool);
18 Future<Integer> result = pool.submit(counter);
19
20 try
21 {
22 System.out.println(result.get() + " matching files.");
23 }
24 catch (ExecutionException e)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 35
36 /**
37 This task counts the files in a directory and its subdirectories that contain a given keyword.
38 */
39 class MatchCounter implements Callable<Integer>
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 57 try
58 {
59 File[] files = directory.listFiles();
60 ArrayList<Future<Integer>> results = new ArrayList<Future<Integer>>();
61
62 for (File file : files)
63 if (file.isDirectory())
64 {
65 MatchCounter counter = new MatchCounter(file, keyword, pool);
Additional matches viewable in cache of v2/v2ch1/ThreadPoolTest/ThreadPoolTest.java. v2/v2ch7/DragSourceTest/DragSourceTest.java (134 lines)
15
16 /**
17 This is a sample drag source for testing purposes. It consists of a list of files
18 in the current directory.
19 */
20 public class DragSourceTest
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30 /**
31 This frame contains a list of files in the current
32 directory with support for dragging files to a drop target.
33 Moved files are removed from the list.
34 */
Additional matches viewable in cache of v2/v2ch7/DragSourceTest/DragSourceTest.java. |
![]() |
|
|
Chapter14/examples/ch14/BackupFilesContentProvider.java (44 lines)
7
8 /**
9 * This class returns the files in the specified directory. If the specified
10 * directory doesn't exist, it returns an empty array.
11 */
12 public class BackupFilesContentProvider implements IStructuredContentProvider {
13 private static final Object[] EMPTY = new Object[] {};
14
15 /**
16 * Gets the files in the specified directory
17 *
18 * @param arg0 a String containing the directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 20 public Object[] getElements(Object arg0) {
21 File file = new File((String) arg0);
22 if (file.isDirectory()) { return file.listFiles(new FileFilter() {
23 public boolean accept(File pathName) {
24 // Ignore directories; return only files
Chapter14/examples/ch14/FileTreeContentProvider.java (78 lines)
17 */
18 public Object[] getChildren(Object arg0) {
19 // Return the files and subdirectories in this directory
20 return ((File) arg0).listFiles();
21 }
Chapter14/examples/ch14/BackupFiles.java (191 lines)
11
12 /**
13 * This class demonstrates CheckboxTableViewer. It allows you to check files to
14 * copy, and copy them to a backup directory.
15 */
16 public class BackupFiles extends ApplicationWindow {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 62 composite.setLayout(new GridLayout(1, false));
63
64 // Create the source directory panel and its controls
65 final Text sourceDir = createFilePanelHelper(composite, "Source Dir:");
66
67 // Create the CheckboxTableViewer to display the files in the source dir
68 final CheckboxTableViewer ctv = CheckboxTableViewer.newCheckList(composite,
69 SWT.BORDER);
70 ctv.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
71 ctv.setContentProvider(new BackupFilesContentProvider());
72 ctv.setLabelProvider(new BackupFilesLabelProvider());
73
74 // Create the destination directory panel and its controls
75 final Text destDir = createFilePanelHelper(composite, "Dest Dir:");
76
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 83 status.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
84
85 // When the source directory changes, change the input for the viewer
86 sourceDir.addModifyListener(new ModifyListener() {
87 public void modifyText(ModifyEvent event) {
88 ctv.setInput(((Text) event.widget).getText());
89 }
90 });
91
92 // When copy is pressed, copy the files
93 copy.addSelectionListener(new SelectionAdapter() {
94 public void widgetSelected(SelectionEvent event) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 98 // Some files are checked; make sure we have a valid destination
99 File dest = new File(destDir.getText());
100 if (dest.isDirectory()) {
101 // Go through each file
102 for (int i = 0, n = files.length; i < n; i++) {
103 copyFile((File) files[i], dest);
104 }
105 } else
106 showMessage("You must select a valid destination directory");
107 } else
108 showMessage("You must select some files to copy");
109 }
110 });
Additional matches viewable in cache of Chapter14/examples/ch14/BackupFiles.java. Chapter08/examples/ch8/xmlview/XmlView.java (190 lines)
13 */
14 public class XmlView {
15 /** The path to the directory containing the images */
16 public static final String IMAGE_PATH = "images"
17 + System.getProperty("file.separator");
18
19 private static final String[] FILTER_NAMES = { "XML Files (*.xml)",
20 "All Files (*.*)"};
21
|
![]() |
|
|
dir_file/KillFilesByName.java (34 lines)
1 import java.io.*;
2 /**
3 * DANGEROUS Program to remove files matching a name in a directory
4 * @author Ian Darwin, http://www.darwinsys.com/
5 */
Additional matches viewable in cache of dir_file/KillFilesByName.java. Contrib/JDBCDriver-Moss/SimpleTextConnection.java (839 lines)
93
94 // Get the directory. It will either be supplied with the URL, in
95 // the property list, or we'll use our current default
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 614 if (file.isDirectory()) {
615
616 // List all of the files in the directory with the .SDF extension
617
618 String entries[] = file.list(filter);
Additional matches viewable in cache of Contrib/JDBCDriver-Moss/SimpleTextConnection.java. tar/TarFile.java (127 lines)
4 /**
5 * Tape Archive Lister, patterned loosely after java.util.ZipFile.
6 * Since, unlike Zip files, there is no central directory, you have to
7 * read the entire file either to be sure of having a particular file's
8 * entry, or to know how many entries there are in the archive.
dir_file/CheckFiles.java (53 lines)
4 /**
5 * Get a list of files, and check if any files are missing.
6 * @author Ian F. Darwin, http://www.darwinsys.com/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 12 System.out.println("CheckFiles starting.");
13 cf.getListFromFile();
14 cf.getListFromDirectory();
15 cf.reportMissingFiles();
16 System.out.println("CheckFiles done.");
17 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 39
40 /** Get list of names from the directory */
41 protected void getListFromDirectory() {
42 listFromDir = new ArrayList();
43 String[] l = new java.io.File(".").list();
44 for (int i=0; i<l.length; i++)
45 listFromDir.add(l[i]);
46 }
47
48 protected void reportMissingFiles() {
49 for (int i=0; i<listFromFile.size(); i++)
50 if (!listFromDir.contains(listFromFile.get(i)))
Additional matches viewable in cache of dir_file/CheckFiles.java. netweb/MkIndex.java (248 lines)
3 import com.darwinsys.io.FileIO;
4
5 /** MkIndex -- make a static index.html for a Java Source directory
6 * <p>
7 * Started life as an awk script that used "ls" to get
8 * the list of files, grep out .class and javadoc output files, |sort.
9 * Now it's all in Java (including the ls-ing and the sorting).
10 *
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 131
132 if (file.isDirectory()) {
133 System.out.println("Indexing directory " + name);
134 File[] files = file.listFiles();
135 for (int i=0; i<files.length; i++) {
136 String fn = files[i].getName();
Additional matches viewable in cache of netweb/MkIndex.java. |
![]() |
|
|
JavaExamples3/je3/io/FileLister.java (212 lines)
18 /**
19 * This class creates and displays a window containing a list of
20 * files and sub-directories in a specified directory. Clicking on an
21 * entry in the list displays more information about it. Double-clicking
22 * on an entry displays it, if a file, or lists it if a directory.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 30 private File currentDir; // The directory currently listed
31 private FilenameFilter filter; // An optional filter for the directory
32 private String[] files; // The directory contents
33 private DateFormat dateFormatter = // To display dates and time correctly
34 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 85 throw new IllegalArgumentException("FileLister: no such directory");
86
87 // Get the (filtered) directory entries
88 files = dir.list(filter);
89
90 // Sort the list of filenames.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 93 // Remove any old entries in the list, and add the new ones
94 list.removeAll();
95 list.add("[Up to Parent Directory]"); // A special case entry
96 for(int i = 0; i < files.length; i++) list.add(files[i]);
97
98 // Display directory name in window titlebar and in the details box
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 111 int i = list.getSelectedIndex() - 1; // minus 1 for Up To Parent entry
112 if (i < 0) return;
113 String filename = files[i]; // Get the selected entry
114 File f = new File(currentDir, filename); // Convert to a File
115 if (!f.exists()) // Confirm that it exists
116 throw new IllegalArgumentException("FileLister: " +
117 "no such file or directory");
118
119 // Get the details about the file or directory, concatenate to a string
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 142 if (i == 0) up(); // Handle first Up To Parent item
143 else { // Otherwise, get filename
144 String name = files[i-1];
145 File f = new File(currentDir, name); // Convert to a File
146 String fullname = f.getAbsolutePath();
147 if (f.isDirectory()) listDirectory(fullname); // List dir
148 else new FileViewer(fullname).show(); // display file
149 }
Additional matches viewable in cache of JavaExamples3/je3/io/FileLister.java. JavaExamples3/je3/io/Delete.java (70 lines)
15 * This class is a static method delete() and a standalone program that
16 * deletes a specified file or directory.
17 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 49
50 // If it is a directory, make sure it is empty
51 if (f.isDirectory()) {
52 String[] files = f.list();
53 if (files.length > 0)
54 fail("Delete: directory not empty: " + filename);
55 }
56
Additional matches viewable in cache of JavaExamples3/je3/io/Delete.java. JavaExamples3/je3/security/SecureService.java (86 lines)
46 out.println();
47 out.println("Attempting to find home directory...");
48 try { out.println(System.getProperty("user.home")); }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 58 File f = new File(dir, "testfile");
59
60 // Check whether we've been given permission to write files to
61 // the tmpdir directory
62 out.println();
63 out.println("Attempting to write a file in " + tmpdir + "...");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 68 catch (Exception e) { out.println("Failed: " + e); }
69
70 // Check whether we've been given permission to read files from
71 // the tmpdir directory
72 out.println();
73 out.println("Attempting to read from " + tmpdir + "...");
JavaExamples3/je3/io/Compress.java (101 lines)
14
15 /**
16 * This class defines two static methods for gzipping files and zipping
17 * directories. It also defines a demonstration program as a nested class.
18 **/
19 public class Compress {
20 /** Gzip the contents of the from file and save in the to file. */
21 public static void gzipFile(String from, String to) throws IOException {
22 // Create stream to read from the from file
23 FileInputStream in = new FileInputStream(from);
24 // Create stream to compress data and write it to the to file.
25 GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(to));
26 // Copy bytes from one stream to the other
27 byte[] buffer = new byte[4096];
28 int bytes_read;
29 while((bytes_read = in.read(buffer)) != -1)
30 out.write(buffer, 0, bytes_read);
31 // And close the streams
32 in.close();
33 out.close();
34 }
35
36 /** Zip the contents of the directory, and save it in the zipfile */
37 public static void zipDirectory(String dir, String zipfile)
38 throws IOException, IllegalArgumentException {
Additional matches viewable in cache of JavaExamples3/je3/io/Compress.java. JavaExamples3/je3/io/FileCopy.java (119 lines)
15 * This class is a standalone program to copy a file, and also defines a
16 * static copy() method that other programs can use to copy files.
17 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 46 if (!from_file.isFile())
47 abort("can't copy directory: " + from_name);
48 if (!from_file.canRead())
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 50
51 // If the destination is a directory, use the source file name
52 // as the destination file name
53 if (to_file.isDirectory())
54 to_file = new File(to_file, from_file.getName());
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 57 // and ask before overwriting it. If the destination doesn't
58 // exist, make sure the directory exists and is writeable.
59 if (to_file.exists()) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 74 else {
75 // If file doesn't exist, check if directory exists and is
76 // writeable. If getParent() returns null, then the directory is
77 // the current dir. so look up the user.dir system property to
78 // find out what that is.
79 String parent = to_file.getParent(); // The destination directory
80 if (parent == null) // If none, use the current directory
81 parent = System.getProperty("user.dir");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 83 if (!dir.exists())
84 abort("destination directory doesn't exist: "+parent);
85 if (dir.isFile())
86 abort("destination is not a directory: " + parent);
87 if (!dir.canWrite())
88 abort("destination directory is unwriteable: " + parent);
89 }
|
![]() |
|
|
jswing2/ch15/FileModel.java (58 lines)
1 // FileModel.java
2 // A custom table model to display information on a directory of files.
3 //
4 import javax.swing.table.*;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 23 public FileModel(String dir) {
24 File pwd = new File(dir);
25 setFileStats(pwd);
26 }
27
28 // Implement the methods of the TableModel interface we're interested
29 // in. Only getRowCount(), getColumnCount() and getValueAt() are
30 // required. The other methods tailor the look of the table.
31 public int getRowCount() { return data.length; }
32 public int getColumnCount() { return titles.length; }
33 public String getColumnName(int c) { return titles[c]; }
34 public Class getColumnClass(int c) { return types[c]; }
35 public Object getValueAt(int r, int c) { return data[r][c]; }
36
37 // Our own method for setting/changing the current directory
38 // being displayed. This method fills the data set with file info
39 // from the given directory. It also fires an update event so this
40 // method could also be called after the table is on display.
41 public void setFileStats(File dir) {
42 String files[] = dir.list();
43 data = new Object[files.length][titles.length];
44
45 for (int i=0; i < files.length; i++) {
46 File tmp = new File(files[i]);
47 data[i][0] = new Boolean(tmp.isDirectory());
48 data[i][1] = tmp.getName();
49 data[i][2] = new Boolean(tmp.canRead());
Additional matches viewable in cache of jswing2/ch15/FileModel.java. jswing2/ch15/TableFeature.java (52 lines)
11
12 String titles[] = new String[] {
13 "Directory?", "File Name", "Read?", "Write?", "Size", "Last Modified"
14 };
15
16 public TableFeature() {
17 super("Simple JTable Test");
18 setSize(300, 200);
19 setDefaultCloseOperation(EXIT_ON_CLOSE);
20
21 File pwd = new File(".");
22 Object[][] stats = getFileStats(pwd);
23
24 JTable jt = new JTable(stats, titles);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 35
36 for (int i=0; i < files.length; i++) {
37 File tmp = new File(files[i]);
38 results[i][0] = new Boolean(tmp.isDirectory());
39 results[i][1] = tmp.getName();
40 results[i][2] = new Boolean(tmp.canRead());
Additional matches viewable in cache of jswing2/ch15/TableFeature.java. jswing2/ch17/SortTreeDemo.java (55 lines)
26 PrettyFile pf = (PrettyFile)current.getUserObject();
27 File f = pf.getFile();
28 if (f.isDirectory()) {
29 String files[] = f.list();
30 // ignore "." files
31 for (int i = 0; i < files.length; i++) {
32 if (files[i].startsWith(".")) continue;
33 PrettyFile tmp = new PrettyFile(pf, files[i]);
34 DefaultMutableTreeNode node = new DefaultMutableTreeNode(tmp);
35 model.insertNodeInto(node, current);
36 if (tmp.getFile().isDirectory()) {
37 fillModel(model, node);
38 }
jswing2/ch12/SimpleFileChooser.java (88 lines)
31 if (option == JFileChooser.APPROVE_OPTION) {
32 File[] sf = chooser.getSelectedFiles();
33 String filelist = "nothing";
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 59 });
60
61 // Create a file chooser that allows you to pick a directory
62 // rather than a file
63 dirButton.addActionListener(new ActionListener() {
64 public void actionPerformed(ActionEvent ae) {
65 JFileChooser chooser = new JFileChooser();
66 chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
67 int option = chooser.showOpenDialog(SimpleFileChooser.this);
68 if (option == JFileChooser.APPROVE_OPTION) {
jswing2/ch12/SimpleFileFilter.java (42 lines)
22 }
23 // Make sure we have a valid (if simplistic) description
24 description = (descr == null ? exts[0] + " files" : descr);
25 }
26
27 public boolean accept(File f) {
28 // We always allow directories, regardless of their extension
29 if (f.isDirectory()) { return true; }
30
31 // Ok, it’s a regular file, so check the extension
|
![]() |
|
|
06/src/com/marinilli/b2/c6/bank/ApplicationHelper.java (296 lines)
92 protected boolean isCached(String item){
93 File file = new File(CACHE_DIR);
94 if(file.exists() && file.isDirectory()) {
95 File[] dirContent = file.listFiles();
96 for(int i = 0; i < dirContent.length; i++) {
97 if(dirContent[i].getName().equals(item))
Additional matches viewable in cache of 06/src/com/marinilli/b2/c6/bank/ApplicationHelper.java. |
![]() |
|
|
javasec/samples/appe/XYZProvider.java (239 lines)
141 while (e.hasMoreElements()) {
142 JarEntry je = (JarEntry) e.nextElement();
143 if (je.isDirectory())
144 continue;
145 // Every file must be signed - except files in META-INF
146 Certificate[] certs = je.getCertificates();
147 if ((certs == null) || (certs.length == 0)) {
|
![]() |
|
|
src/com/oreilly/servlet/MultipartRequest.java (489 lines)
21 * interface of <code>HttpServletRequest</code>, making it familiar to use.
22 * It uses a "push" model where any incoming files are read and saved directly
23 * to disk in the constructor. If you wish to have more flexibility, e.g.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 74 /**
75 * Constructs a new MultipartRequest to handle the specified request,
76 * saving any uploaded files to the given directory, and limiting the
77 * upload size to 1 Megabyte. If the content is too large, an
78 * IOException is thrown. This constructor actually parses the
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 81 *
82 * @param request the servlet request.
83 * @param saveDirectory the directory in which to save any uploaded files.
84 * @exception IOException if the uploaded content is larger than 1 Megabyte
85 * or there's a problem reading or parsing the request.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 92 /**
93 * Constructs a new MultipartRequest to handle the specified request,
94 * saving any uploaded files to the given directory, and limiting the
95 * upload size to the specified length. If the content is too large, an
96 * IOException is thrown. This constructor actually parses the
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 99 *
100 * @param request the servlet request.
101 * @param saveDirectory the directory in which to save any uploaded files.
102 * @param maxPostSize the maximum size of the POST content.
103 * @exception IOException if the uploaded content is larger than
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 112 /**
113 * Constructs a new MultipartRequest to handle the specified request,
114 * saving any uploaded files to the given directory, and limiting the
115 * upload size to the specified length. If the content is too large, an
116 * IOException is thrown. This constructor actually parses the
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 119 *
120 * @param request the servlet request.
121 * @param saveDirectory the directory in which to save any uploaded files.
122 * @param encoding the encoding of the response, such as ISO-8859-1
123 * @exception IOException if the uploaded content is larger than
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 132 /**
133 * Constructs a new MultipartRequest to handle the specified request,
134 * saving any uploaded files to the given directory, and limiting the
135 * upload size to the specified length. If the content is too large, an
136 * IOException is thrown. This constructor actually parses the
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 139 *
140 * @param request the servlet request.
141 * @param saveDirectory the directory in which to save any uploaded files.
142 * @param maxPostSize the maximum size of the POST content.
143 * @param encoding the encoding of the response, such as ISO-8859-1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 154 /**
155 * Constructs a new MultipartRequest to handle the specified request,
156 * saving any uploaded files to the given directory, and limiting the
157 * upload size to the specified length. If the content is too large, an
158 * IOException is thrown. This constructor actually parses the
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 161 *
162 * @param request the servlet request.
163 * @param saveDirectory the directory in which to save any uploaded files.
164 * @param maxPostSize the maximum size of the POST content.
165 * @param encoding the encoding of the response, such as ISO-8859-1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 176 /**
177 * Constructs a new MultipartRequest to handle the specified request,
178 * saving any uploaded files to the given directory, and limiting the
179 * upload size to the specified length. If the content is too large, an
180 * IOException is thrown. This constructor actually parses the
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 186 *
187 * @param request the servlet request.
188 * @param saveDirectory the directory in which to save any uploaded files.
189 * @param maxPostSize the maximum size of the POST content.
190 * @param encoding the encoding of the response, such as ISO-8859-1
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 216 // Check saveDirectory is writable
217 if (!dir.canWrite())
218 throw new IllegalArgumentException("Not writable: " + saveDirectory);
219
220 // Parse the incoming multipart, storing files in the dir provided,
221 // and populate the meta objects which describe what we found
222 MultipartParser parser =
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 272 else {
273 // The field did not contain a file
274 files.put(name, new UploadedFile(null, null, null, null));
275 }
276 }
277 }
278 }
279
280 /**
281 * Constructor with an old signature, kept for backward compatibility.
282 * Without this constructor, a servlet compiled against a previous version
283 * of this class (pre 1.4) would have to be recompiled to link with this
284 * version. This constructor supports the linking via the old signature.
285 * Callers must simply be careful to pass in an HttpServletRequest.
286 *
287 */
288 public MultipartRequest(ServletRequest request,
289 String saveDirectory) throws IOException {
290 this((HttpServletRequest)request, saveDirectory);
291 }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 302 String saveDirectory,
303 int maxPostSize) throws IOException {
304 this((HttpServletRequest)request, saveDirectory, maxPostSize);
305 }
306
307 /**
308 * Returns the names of all the parameters as an Enumeration of
309 * Strings. It returns an empty Enumeration if there are no parameters.
310 *
311 * @return the names of all the parameters as an Enumeration of Strings.
312 */
313 public Enumeration getParameterNames() {
314 return parameters.keys();
315 }
316
317 /**
318 * Returns the names of all the uploaded files as an Enumeration of
319 * Strings. It returns an empty Enumeration if there are no uploaded
320 * files. Each file name is the name specified by the form, not by
Additional matches viewable in cache of src/com/oreilly/servlet/MultipartRequest.java. jservlet2-examples/ch04/UploadTest.java (67 lines)
17
18 // Construct a MultipartRequest to help read the information.
19 // Pass in the request, a directory to save files to, and the
20 // maximum POST size we should attempt to handle.
21 // Here we (rudely) write to the server root and impose 5 Meg limit.
Additional matches viewable in cache of jservlet2-examples/ch04/UploadTest.java. |
![]() |
|
|
JavaExamples2/com/davidflanagan/examples/io/FileLister.java (212 lines)
17 /**
18 * This class creates and displays a window containing a list of
19 * files and sub-directories in a specified directory. Clicking on an
20 * entry in the list displays more information about it. Double-clicking
21 * on an entry displays it, if a file, or lists it if a directory.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 29 private File currentDir; // The directory currently listed
30 private FilenameFilter filter; // An optional filter for the directory
31 private String[] files; // The directory contents
32 private DateFormat dateFormatter = // To display dates and time correctly
33 DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 84 throw new IllegalArgumentException("FileLister: no such directory");
85
86 // Get the (filtered) directory entries
87 files = dir.list(filter);
88
89 // Sort the list of filenames. Prior to Java 1.2, you could use
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 93 // Remove any old entries in the list, and add the new ones
94 list.removeAll();
95 list.add("[Up to Parent Directory]"); // A special case entry
96 for(int i = 0; i < files.length; i++) list.add(files[i]);
97
98 // Display directory name in window titlebar and in the details box
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 111 int i = list.getSelectedIndex() - 1; // minus 1 for Up To Parent entry
112 if (i < 0) return;
113 String filename = files[i]; // Get the selected entry
114 File f = new File(currentDir, filename); // Convert to a File
115 if (!f.exists()) // Confirm that it exists
116 throw new IllegalArgumentException("FileLister: " +
117 "no such file or directory");
118
119 // Get the details about the file or directory, concatenate to a string
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 142 if (i == 0) up(); // Handle first Up To Parent item
143 else { // Otherwise, get filename
144 String name = files[i-1];
145 File f = new File(currentDir, name); // Convert to a File
146 String fullname = f.getAbsolutePath();
147 if (f.isDirectory()) listDirectory(fullname); // List dir
148 else new FileViewer(fullname).show(); // display file
149 }
Additional matches viewable in cache of JavaExamples2/com/davidflanagan/examples/io/FileLister.java. JavaExamples2/com/davidflanagan/examples/io/Delete.java (69 lines)
14 * This class is a static method delete() and a standalone program that
15 * deletes a specified file or directory.
16 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 48
49 // If it is a directory, make sure it is empty
50 if (f.isDirectory()) {
51 String[] files = f.list();
52 if (files.length > 0)
53 fail("Delete: directory not empty: " + filename);
54 }
55
Additional matches viewable in cache of JavaExamples2/com/davidflanagan/examples/io/Delete.java. JavaExamples2/com/davidflanagan/examples/security/SecureService.java (85 lines)
45 out.println();
46 out.println("Attempting to find home directory...");
47 try { out.println(System.getProperty("user.home")); }
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 57 File f = new File(dir, "testfile");
58
59 // Check whether we've been given permission to write files to
60 // the tmpdir directory
61 out.println();
62 out.println("Attempting to write a file in " + tmpdir + "...");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 67 catch (Exception e) { out.println("Failed: " + e); }
68
69 // Check whether we've been given permission to read files from
70 // the tmpdir directory
71 out.println();
72 out.println("Attempting to read from " + tmpdir + "...");
JavaExamples2/com/davidflanagan/examples/io/Compress.java (100 lines)
13
14 /**
15 * This class defines two static methods for gzipping files and zipping
16 * directories. It also defines a demonstration program as a nested class.
17 **/
18 public class Compress {
19 /** Gzip the contents of the from file and save in the to file. */
20 public static void gzipFile(String from, String to) throws IOException {
21 // Create stream to read from the from file
22 FileInputStream in = new FileInputStream(from);
23 // Create stream to compress data and write it to the to file.
24 GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(to));
25 // Copy bytes from one stream to the other
26 byte[] buffer = new byte[4096];
27 int bytes_read;
28 while((bytes_read = in.read(buffer)) != -1)
29 out.write(buffer, 0, bytes_read);
30 // And close the streams
31 in.close();
32 out.close();
33 }
34
35 /** Zip the contents of the directory, and save it in the zipfile */
36 public static void zipDirectory(String dir, String zipfile)
37 throws IOException, IllegalArgumentException {
Additional matches viewable in cache of JavaExamples2/com/davidflanagan/examples/io/Compress.java. JavaExamples2/com/davidflanagan/examples/io/FileCopy.java (116 lines)
14 * This class is a standalone program to copy a file, and also defines a
15 * static copy() method that other programs can use to copy files.
16 **/
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 43 if (!from_file.isFile())
44 abort("can't copy directory: " + from_name);
45 if (!from_file.canRead())
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 47
48 // If the destination is a directory, use the source file name
49 // as the destination file name
50 if (to_file.isDirectory())
51 to_file = new File(to_file, from_file.getName());
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 54 // and ask before overwriting it. If the destination doesn't
55 // exist, make sure the directory exists and is writeable.
56 if (to_file.exists()) {
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 71 else {
72 // If file doesn't exist, check if directory exists and is
73 // writeable. If getParent() returns null, then the directory is
74 // the current dir. so look up the user.dir system property to
75 // find out what that is.
76 String parent = to_file.getParent(); // The destination directory
77 if (parent == null) // If none, use the current directory
78 parent = System.getProperty("user.dir");
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 80 if (!dir.exists())
81 abort("destination directory doesn't exist: "+parent);
82 if (dir.isFile())
83 abort("destination is not a directory: " + parent);
84 if (!dir.canWrite())
85 abort("destination directory is unwriteable: " + parent);
86 }
|
![]() |
|
|
jentnutexamples/servlets/FileServlet.java (48 lines)
12 import java.io.*;
13
14 public class FileServlet extends HttpServlet {
15
16 public void doGet(HttpServletRequest req, HttpServletResponse resp)
17 throws ServletException, IOException {
18
19 File r;
20 FileReader fr;
21 BufferedReader br;
22 try {
23 r = new File(req.getParameter("filename"));
24 fr = new FileReader(r);
25 br = new BufferedReader(fr);
26 if(!r.isFile()) { // Must be a directory or something else
27 resp.sendError(resp.SC_NOT_FOUND);
28 return;
|
|
|