File Dialogs  «Prev 


Choosing Files with the File Dialog Boxes

When you consider all the difficulties of writing file access code that works on all the platforms Java supports, you can become grateful that applets are not allowed to write files. Although this limits the sort of applets you can write, perhaps what's really needed is not unlimited (or even limited) file access but rather some non-file-oriented persistent storage mechanism, probably some sort of database, that hides the idiosyncrasies of each individual platform.
JavaSoft created a mechanism known as JavaSpaces.


public class FileDialog extends Dialog
A file dialog is almost completely implemented by a native peer. Your program does not add components to a file dialog or handle user interaction with event listeners. It just displays the dialog and retrieves the name and directory of the file the user chose after the dialog is dismissed. Since applets normally cannot read or write files, file dialogs are primarily useful only in applications. Nonetheless, there is no specific security manager check to see whether file dialogs are allowed. Trusted applets can display file dialogs, retrieve the name and path of the file selected, and send that information back to the originating host over the network. Although this is a very minor security hole, since it only exposes the name and path of a single file selected by the user, it is still on the worrisome side for those individuals that are concerned. Certainly, you cannot count on being allowed to use a file dialog in an applet, nor can you be guaranteed that it isn't allowed either.